-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python tests: Explicitly mark async
functions instead of relying on pytest-aiohttp
magic
#8176
Comments
AnyIO ships with a pytest plugin with the same |
async
functions instead of relying on aiohttp
magicasync
functions instead of relying on pytest-aiohttp
magic
Whichever library we choose, we should do some due diligence to see how it handles the fringes of setting up and tearing down the async environments that it runs test functions in. I only tenuously understand these concerns, but they seem surprisingly nuanced. Here are some questions I just opened on But, on the other hand, it's not like we get to avoid these concerns by doing nothing and sticking with |
Now that #8228 has been merged, we have Due diligence still required, but if anyio's setup/teardown logic looks sound, then this seems like a tempting option |
In terms of some really cursory inspection of the anyio test runner for the asyncio backend, it looks like anyio will:
It does not appear to shutdown the default executor explicitely. So far find no evidence that |
Upon even further digging, it appears that in asyncio, |
I tried implementing this with AnyIO's pytest plugin, but I found that its API has an unfortunate trap. If you have something like this: @pytest.fixture
async def my_async_fixture():
...
def my_non_async_test_func(fixture):
... Then you'd expect This is because Here's the specific fixture that tipped me off, used by this test. At best, this causes confusing errors, and at worst, it makes tests silently run under the wrong environment. After migrating around 90% of the I believe the |
Our Python tests define asynchronous test functions like this:
pytest
doesn't natively support runningasync
functions. It currently happens to magically work for us because we have thepytest-aiohttp
plugin installed as a dev dependency.For explicitness and normalcy, we instead want to:
pytest-asyncio
as a dev dependency.async
test functions withpytest.mark.asyncio
.pytest-aiohttp
, assuming it's not used anywhere else.The text was updated successfully, but these errors were encountered: