Skip to content

Conversation

@CodeVishal-17
Copy link

Resolves #4778

What is being addressed

Pytest emits a PytestDeprecationWarning indicating that the configuration option
asyncio_default_fixture_loop_scope is unset. This warning will become an error
in future versions of pytest-asyncio if not explicitly configured.

How is this addressed

  • Explicitly set asyncio_mode = auto and
    asyncio_default_fixture_loop_scope = function in api_app/pytest.ini
    to align with pytest-asyncio recommendations.
  • This removes the deprecation warning and future-proofs the test configuration.

@CodeVishal-17 CodeVishal-17 requested a review from a team as a code owner January 5, 2026 15:55
@github-actions github-actions bot added the external PR from an external contributor label Jan 5, 2026
@JC-wk
Copy link
Collaborator

JC-wk commented Jan 7, 2026

Hi @CodeVishal-17 have you been able to run pytest ./api_app/ in the devcontainer with this config set, I'm seeing some tests fail when they are function scoped. EDIT: This is only when I upgrade to the latest pytest-asyncio pip install --upgrade pytest-asyncio

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)
I think we can use strict for asyncio_mode
When I have set it to module scope the tests pass e.g

[pytest]
filterwarnings =
    error
asyncio_mode = strict
asyncio_default_fixture_loop_scope = function

Also I've added a pyproject.toml at the root to specify options for bandit and pytest in a single file as when running pytest --ignore ./e2e_tests/ it seems to ignore the pytest.ini in the subfolder or at least still defaults to None for some of the tests.
See this branch https://github.com/JC-wk/AzureTRE/tree/fix/pytest-asyncio-deprecation and these changes main...JC-wk:AzureTRE:fix/pytest-asyncio-deprecation

Copy link
Collaborator

@JC-wk JC-wk left a 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

@CodeVishal-17
Copy link
Author

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.

@CodeVishal-17
Copy link
Author

@microsoft-github-policy-service agree

@CodeVishal-17
Copy link
Author

@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.

Copy link
Collaborator

@JC-wk JC-wk left a 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')
Copy link
Collaborator

@JC-wk JC-wk Jan 7, 2026

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)

@CodeVishal-17
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.

2 participants