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

Fix tests for Python 3.14 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

musicinmybrain
Copy link

Use the event_loop fixture for tests that need one.

Without this, many tests fail in Python 3.14.0a2 because asyncio.get_event_loop() no longer automatically starts an event loop, instead raising a RuntimeError if there is no current event loop. See https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.get_event_loop, https://docs.python.org/dev/whatsnew/3.14.html#id3, and python/cpython#126353.

For documentation on the fixture, see https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures/#event-loop.

Additionally, configure asyncio_default_fixture_loop_scope to function, which will be the default in a future release of pytest-asyncio. This isn’t specifically required for Python 3.14, but it fixes warnings like this:

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"

Without this, many tests fail in Python 3.14.0a2 because
`asyncio.get_event_loop()` no longer automatically starts an event loop,
instead raising a `RuntimeError` if there is no current event loop. See
https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.get_event_loop,
https://docs.python.org/dev/whatsnew/3.14.html#id3, and
python/cpython#126353.

For documentation on the fixture, see
https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures/#event-loop.
Fixes:

```
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"
```
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 this pull request may close these issues.

1 participant