Skip to content
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

We are redefining the event_loop fixture of pytest-asyncio in a deprecated way #14559

Closed
chrisguidry opened this issue Jul 11, 2024 · 0 comments · Fixed by #15523
Closed

We are redefining the event_loop fixture of pytest-asyncio in a deprecated way #14559

chrisguidry opened this issue Jul 11, 2024 · 0 comments · Fixed by #15523
Assignees

Comments

@chrisguidry
Copy link
Collaborator

This warning has started to show up from pytest-asyncio and we are currently suppressing it:

E               DeprecationWarning: The event_loop fixture provided by pytest-asyncio has been redefined in
E               /home/runner/work/prefect/prefect/tests/conftest.py:211
E               Replacing the event_loop fixture with a custom implementation is deprecated
E               and will lead to errors in the future.
E               If you want to request an asyncio event loop with a scope other than function
E               scope, use the "scope" argument to the asyncio mark when marking the tests.
E               If you want to return different types of event loops, use the event_loop_policy
E               fixture.
@chrisguidry chrisguidry self-assigned this Jul 11, 2024
chrisguidry added a commit that referenced this issue Sep 27, 2024
We were blocked from upgrading `pytest` because we were redefining the
`event_loop` fixture, which has been deprecated for some time in
`pytest-asyncio`.  Here we remove that fixture and set the appropriate
configuration per their [docs][1]:

* Automatically marks all async tests as being marked with the `asyncio` fixture
  set to `loop_scope="session"
* Make the default fixture loop scope `session` as well (in `setup.cfg`)
* In the case where we need to switch to a different policy, like for Windows
  support, override the `event_loop_policy` fixture

One issue emerged here, where any test that called `asyncio.run` or `anyio.run`
would leave the test clearing the event loop from the `'MainThread'`, thus
poisoning the environment for all subsequent tests.  Adding a fixture that
restores the session-level `pytest-asyncio` event loop after each test function
prevents that issue.

Fixes #14559

[1]: https://pytest-asyncio.readthedocs.io/en/latest/how-to-guides/run_session_tests_in_same_loop.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant