I am writing my first test (unit test with Pytest), that contains AioHttpClient with BasicAuth (with username and poassword). My function's structure:
async def example_function(some parameters):
(...)
try:
synth_url = os.getenv("SYNTH_URL", 'https://...')
async with AioHttpClient.session().post(synth_url, data=data_in, auth=aiohttp.BasicAuth(
'username', os.getenv("MY_PASSWORD"))) as resp:
if resp.ok:
return await resp.read()
else:
(...)
What is the best practice when testing such function? I have tried to use monkeypatch or mock the AioHttpClient but without any success so far. Thank you.