atlassian / atlassian/asap-authentication-python
HTTPSPublicKeyRetriever caches asyncio event loop - pytest-asyncio issues
- Dominant language
- Python
- Stars
- 26
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Hey there. I'm using `atlassian_jwt_auth` in an ayncio context; specifically using [pytest-asyncio](https://pypi.org/project/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:
```python
@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](https://github.com/atlassian/asap-authentication-python/blob/master/atlassian_jwt_auth/contrib/aiohttp/key.py#L23-L26) of `client.loop != self.loop` fixes the issue, but `client.loop` is [deprecated in aiohttp](https://github.com/aio-libs/aiohttp/blob/v3.7.4.post0/aiohttp/client.py#L995-L1001) and actually has been removed in the newest master branch.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.