delfick / alt-pytest-asyncio

An alternative plugin for pytest to make it support async tests and fixtures
https://alt-pytest-asyncio.readthedocs.io
MIT License
27 stars 5 forks source link

call shutdown_asyncgens() on event loop in OverrideLoop.__exit__() #10

Closed brianmaissy closed 3 years ago

brianmaissy commented 3 years ago

Before closing the temporary event loop in OverrideLoop.__exit__(), it might be a good idea to call loop.shutdown_asyncgens(), like asyncio.run() does in its cleanup.

delfick commented 3 years ago

That is a good point. I must have had a reason why I didn't but I can't remember why that would be. I'll have a look later.

It's based off my version of this in Photons which at the time did include a version of shutdown_asyngens

delfick commented 3 years ago

@brianmaissy I'm struggling to remember the situation where cancel_all_tasks isn't enough to shutdown asyncgens and struggling to write a test where doing a loop.shutdown_asyncgens makes a difference. Do you have a code example of where not calling shutdown_asyncgens causes a problem?

delfick commented 3 years ago

There we go, it took me an hour and a half to find a scenario where it makes a difference lol.

How does #11 look @brianmaissy ?

brianmaissy commented 3 years ago

Wow thanks for the fast response! I'm not familiar with the details of our use case, I asked my colleague @nzig to take a look at it

nzig commented 3 years ago

This can be closed now thanks to #11.