Skip to content

Instantly share code, notes, and snippets.

@yaraslaublonski
Created August 29, 2022 16:31
Show Gist options
  • Save yaraslaublonski/0873127b3d6140f1bfff0e75c340ff44 to your computer and use it in GitHub Desktop.
Save yaraslaublonski/0873127b3d6140f1bfff0e75c340ff44 to your computer and use it in GitHub Desktop.
httpx test client
import asyncio
from httpx import AsyncClient
class CustomClient(AsyncClient):
async def make_query(self, url: str) -> int:
async with self as client:
await client.get(url)
async def run():
test_client: CustomClient = CustomClient()
try:
await test_client.make_query('https://github.com')
await test_client.make_query('https://github.com')
except RuntimeError:
print('Cannot open the same self-client 2 times')
asyncio.run(run())
# Cannot open the same self-client 2 times
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment