-
Notifications
You must be signed in to change notification settings - Fork 174
Fix pytest-asyncio deprecation warning by setting default loop scope #4802
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
base: main
Are you sure you want to change the base?
Fix pytest-asyncio deprecation warning by setting default loop scope #4802
Conversation
|
Hi @CodeVishal-17 have you been able to run I've been able to fix them by using @pytest.fixture instead of @pytest_asyncio.fixture for those tests setups Those test setups aren't async) Also I've added a pyproject.toml at the root to specify options for bandit and pytest in a single file as when running |
JC-wk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works with pytest-asyncio v0.24.0 current devcontainer version but not with v1.3.0 (latest)
try with pip install --upgrade pytest-asyncio
|
Thanks for the clarification 👍 That makes sense — I was testing against pytest-asyncio==0.24.0, which explains why it passes locally but fails with v1.3.0. I’ll upgrade to the latest version and adjust the fixtures accordingly. |
|
@microsoft-github-policy-service agree |
|
@JC-wk Thanks for the clarification! I upgraded locally to pytest-asyncio==1.3.0 and reproduced the issue. I’ve fixed the async fixtures to use @pytest_asyncio.fixture (including making the app fixture async) and verified that the pytest-asyncio deprecation / loop-scope issue is resolved under asyncio_mode=strict. Local test collection failures are due to missing optional runtime dependencies (Azure SDKs / FastAPI / Starlette), which are provided in CI and unrelated to this change. Please let me know if anything else needs adjustment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other change required is in, then all the tests pass for me
api_app/tests_ma/test_api/test_routes/test_airlock.py
change line 130 to @pytest.fixture(autouse=True, scope='class')
change line 306 to @pytest.fixture(autouse=True, scope='class')
see main...JC-wk:AzureTRE:fix/pytest-asyncio-deprecation#diff-5013d846e8403adeed48f3a9b720e7c4b610b02a783a54854bc0432d84bcd22aL130-R130
| return inner | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture(scope='module') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my fix is just to change this to @pytest.fixture(scope='module') rather than making the method async (remove the _asyncio)
|
@JC-wk thanks again for the detailed review! I’ve applied the last requested change (switching the remaining fixtures to @pytest.fixture with the suggested scopes), and all tests now pass locally for me under pytest-asyncio >= 1.3.0. Could you please take another look when you get a chance? Happy to adjust anything further if needed. |
Resolves #4778
What is being addressed
Pytest emits a PytestDeprecationWarning indicating that the configuration option
asyncio_default_fixture_loop_scopeis unset. This warning will become an errorin future versions of pytest-asyncio if not explicitly configured.
How is this addressed
asyncio_mode = autoandasyncio_default_fixture_loop_scope = functioninapi_app/pytest.inito align with pytest-asyncio recommendations.