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

Test for, and suppress, additional get_event_loop() DeprecationWarnings #817

Merged
merged 12 commits into from
May 14, 2024
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
strategy:
matrix:
os: [ubuntu, windows]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10.8', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 6 additions & 2 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,9 @@ def _temporary_event_loop_policy(policy: AbstractEventLoopPolicy) -> Iterator[No
# subsequent tests from side-effects. We close this loop before restoring
# the old loop to avoid ResourceWarnings.
try:
asyncio.get_event_loop().close()
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
asyncio.get_event_loop().close()
except RuntimeError:
pass
asyncio.set_event_loop(old_loop)
Expand Down Expand Up @@ -891,7 +893,9 @@ def wrap_in_sync(
@functools.wraps(func)
def inner(*args, **kwargs):
coro = func(*args, **kwargs)
_loop = asyncio.get_event_loop()
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
_loop = asyncio.get_event_loop()
task = asyncio.ensure_future(coro, loop=_loop)
try:
_loop.run_until_complete(task)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import functools
import warnings

import pytest

Expand Down Expand Up @@ -33,7 +34,11 @@ async def port_afinalizer():
# RuntimeError is raised if task is created on a different loop
await finalizer

asyncio.get_event_loop().run_until_complete(port_afinalizer())
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
loop = asyncio.get_event_loop()

loop.run_until_complete(port_afinalizer())
SyntaxColoring marked this conversation as resolved.
Show resolved Hide resolved

worker = asyncio.ensure_future(asyncio.sleep(0.2))
request.addfinalizer(functools.partial(port_finalizer, worker))
Expand Down
11 changes: 10 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.14.0
envlist = py38, py39, py310, py311, py312, pytest-min, docs
envlist = py38, py39, py3108, py310, py311, py312, pytest-min, docs
isolated_build = true
passenv =
CI
Expand All @@ -25,6 +25,14 @@ commands = make test
allowlist_externals =
make

[testenv: py3108]
# Python 3.10.8 is the most recent version that triggers
# https://github.com/pytest-dev/pytest-asyncio/issues/757.
#
# We need to set basepython explicitly here because if we just added "py3109" to
# envlist, tox would interpret that as "any py310".
basepython = python3.10.8

[testenv:docs]
extras = docs
deps =
Expand All @@ -39,6 +47,7 @@ allowlist_externals =
python =
3.8: py38, pytest-min
3.9: py39
3.10.9: py3109
3.10: py310
3.11: py311
3.12: py312
Expand Down