Skip to content

Fix pytest asyncio deprecation warning - #5055

Open
James Chapman (JC-wk) wants to merge 6 commits into
microsoft:mainfrom
JC-wk:fix/pytest-asyncio-deprecation
Open

Fix pytest asyncio deprecation warning#5055
James Chapman (JC-wk) wants to merge 6 commits into
microsoft:mainfrom
JC-wk:fix/pytest-asyncio-deprecation

Conversation

@JC-wk

@JC-wk James Chapman (JC-wk) commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Resolves #4778

Summary

This PR fixes a pytest-asyncio deprecation warning by explicitly configuring the asyncio mode and default event loop scope for test fixtures.

Details

when pytest --ignore e2e_tests is ran from the root (as documented) Pytest emits a PytestDeprecationWarning indicating that the configuration option
asyncio_default_fixture_loop_scope is unset. With newer versions of
pytest-asyncio (>= 1.3.0), this will become an error unless explicitly configured.

PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

How is this addressed

  • Sets asyncio_default_fixture_loop_scope = function in pyproject.toml
  • Updates async fixtures and test markers to be compatible with strict mode
  • Ensures async client fixtures properly manage lifecycle using async context managers

All tests pass locally under pytest-asyncio >= 1.24.0.

@JC-wk
James Chapman (JC-wk) requested a review from a team as a code owner August 24, 2026 14:20
Copilot AI balanced review requested due to automatic review settings August 24, 2026 14:20
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Unit Test Results

755 tests   755 ✅  9s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 473bb15.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Configures pytest-asyncio explicitly to eliminate deprecation warnings and support strict mode.

Changes:

  • Sets function-scoped event loops and strict asyncio mode.
  • Corrects synchronous fixtures to use pytest.fixture.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pyproject.toml Adds root pytest-asyncio configuration.
api_app/pytest.ini Adds API-specific asyncio configuration.
api_app/tests_ma/test_api/conftest.py Corrects the synchronous app fixture decorator.
api_app/tests_ma/test_api/test_routes/test_airlock.py Corrects synchronous fixture decorators.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread pyproject.toml
@JC-wk James Chapman (JC-wk) added the external PR from an external contributor label Aug 24, 2026
Copilot AI review requested due to automatic review settings August 24, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@JC-wk James Chapman (JC-wk) changed the title Fix/pytest asyncio deprecation Fix pytest asyncio deprecation warning Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rudolphjacksonm

Copy link
Copy Markdown
Collaborator

/test 473bb15

@github-actions

Copy link
Copy Markdown

🤖 pr-bot 🤖

🏃 Running tests: https://github.com/microsoft/AzureTRE/actions/runs/32888275123 (with refid e3365a94)

(in response to this comment from Jack Morris (@rudolphjacksonm))

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.

5 participants