Closed yvdlima closed 4 years ago
Yeah I know exactly how you feel with this one :smile:. The issue is that's exactly how boto3 works so the aim was to mimic that behaviour.
You can make a fixture that will return an aioboto3 client like here https://github.com/terrycain/aioboto3/blob/master/tests/conftest.py#L80-L94
Does that help?
Feel free to add some documentation around using this with pytest if you want
Description
I was writing tests with Pytest which uses multiple event loops and due to the global DEFAULT_SESSION behavior I had a bit of trouble.
Pytest loop fixture is
function
scoped which recreates the asyncio loop every time a test runs. In my case I had a client factory which interacted with aioboto3, the first test would trigger the creation of the DEFAULT_SESSION but subsequent tests will fail as they will always refer to the loop of the DEFAULT_SESSION which is closed. Even if you set the loop in theclient
orresource
call the loop of the DEFAULT_SESSION will be used.I'm not sure if this is the intended design and just missing in the documentation and examples or if it is a bug, either way I'm willing to open a PR to fix it after knowing your thoughts.
What I Did
This is how I quickly fixed for my tests:
It does feels like a bad fix so I will just rewrite my code to use the
aioboto3.session.Session.resource
instead as it will use the correct loop. However this is not documented and not shown in any example