asap-authentication-python icon indicating copy to clipboard operation
asap-authentication-python copied to clipboard

HTTPSPublicKeyRetriever caches asyncio event loop - pytest-asyncio issues

Open tildedave opened this issue 3 years ago • 0 comments

Hey there. I'm using atlassian_jwt_auth in an ayncio context; specifically using pytest-asyncio for the event loop creation. By default this library creates a new event loop for each test. (This is my desired behavior.)

However when running two tests that both utilize the HTTPSPublicKeyRetriever, the second test fails because the cached HTTPSPublicKeyRetriever._class_session is used with a now-shutdown event loop.

I've gotten around this with a fixture like so:

@pytest.fixture(autouse=True)
async def clean_https_session():
    yield
    await HTTPSPublicKeyRetriever._class_session.close()
    HTTPSPublicKeyRetriever._class_session = None

However this feels sort of wacky. Ideally I'd like the library to detect this and invalidate the _class_session either when the loop is shut down or when the session is gotten.

Adding a conditional here of client.loop != self.loop fixes the issue, but client.loop is deprecated in aiohttp and actually has been removed in the newest master branch.

tildedave avatar Jun 16 '21 21:06 tildedave