Skip to content

Commit 25801be

Browse files
tests: handle Python 3.14 DefaultEventLoopPolicy deprecation warnings
1 parent 9378937 commit 25801be

File tree

5 files changed

+95
-20
lines changed

5 files changed

+95
-20
lines changed

tests/markers/test_class_scope.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import sys
67
from textwrap import dedent
78

89
import pytest
@@ -143,8 +144,15 @@ async def test_does_not_use_custom_event_loop_policy():
143144
"""
144145
)
145146
)
146-
result = pytester.runpytest("--asyncio-mode=strict")
147-
result.assert_outcomes(passed=2)
147+
pytest_args = ["--asyncio-mode=strict"]
148+
if sys.version_info >= (3, 14):
149+
pytest_args.extend(["-W", "default"])
150+
result = pytester.runpytest(*pytest_args)
151+
if sys.version_info >= (3, 14):
152+
result.assert_outcomes(passed=2, warnings=3)
153+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
154+
else:
155+
result.assert_outcomes(passed=2)
148156

149157

150158
def test_asyncio_mark_respects_parametrized_loop_policies(
@@ -175,8 +183,15 @@ async def test_parametrized_loop(self, request):
175183
"""
176184
)
177185
)
178-
result = pytester.runpytest("--asyncio-mode=strict")
179-
result.assert_outcomes(passed=2)
186+
pytest_args = ["--asyncio-mode=strict"]
187+
if sys.version_info >= (3, 14):
188+
pytest_args.extend(["-W", "default"])
189+
result = pytester.runpytest(*pytest_args)
190+
if sys.version_info >= (3, 14):
191+
result.assert_outcomes(passed=2, warnings=2)
192+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
193+
else:
194+
result.assert_outcomes(passed=2)
180195

181196

182197
def test_asyncio_mark_provides_class_scoped_loop_to_fixtures(

tests/markers/test_function_scope.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from textwrap import dedent
45

56
from pytest import Pytester
@@ -119,8 +120,15 @@ async def test_uses_custom_event_loop_policy():
119120
"""
120121
),
121122
)
122-
result = pytester.runpytest("--asyncio-mode=strict")
123-
result.assert_outcomes(passed=1)
123+
pytest_args = ["--asyncio-mode=strict"]
124+
if sys.version_info >= (3, 14):
125+
pytest_args.extend(["-W", "default"])
126+
result = pytester.runpytest(*pytest_args)
127+
if sys.version_info >= (3, 14):
128+
result.assert_outcomes(passed=1, warnings=2)
129+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
130+
else:
131+
result.assert_outcomes(passed=1)
124132

125133

126134
def test_asyncio_mark_respects_parametrized_loop_policies(
@@ -157,8 +165,15 @@ async def test_parametrized_loop():
157165
"""
158166
)
159167
)
160-
result = pytester.runpytest("--asyncio-mode=strict")
161-
result.assert_outcomes(passed=2)
168+
pytest_args = ["--asyncio-mode=strict"]
169+
if sys.version_info >= (3, 14):
170+
pytest_args.extend(["-W", "default"])
171+
result = pytester.runpytest(*pytest_args)
172+
if sys.version_info >= (3, 14):
173+
result.assert_outcomes(passed=2, warnings=3)
174+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
175+
else:
176+
result.assert_outcomes(passed=2)
162177

163178

164179
def test_asyncio_mark_provides_function_scoped_loop_to_fixtures(

tests/markers/test_module_scope.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from textwrap import dedent
45

56
from pytest import Pytester
@@ -87,8 +88,15 @@ async def test_does_not_use_custom_event_loop_policy():
8788
"""
8889
),
8990
)
90-
result = pytester.runpytest("--asyncio-mode=strict")
91-
result.assert_outcomes(passed=2)
91+
pytest_args = ["--asyncio-mode=strict"]
92+
if sys.version_info >= (3, 14):
93+
pytest_args.extend(["-W", "default"])
94+
result = pytester.runpytest(*pytest_args)
95+
if sys.version_info >= (3, 14):
96+
result.assert_outcomes(passed=2, warnings=3)
97+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
98+
else:
99+
result.assert_outcomes(passed=2)
92100

93101

94102
def test_asyncio_mark_respects_parametrized_loop_policies(
@@ -119,8 +127,15 @@ async def test_parametrized_loop():
119127
"""
120128
)
121129
)
122-
result = pytester.runpytest("--asyncio-mode=strict")
123-
result.assert_outcomes(passed=2)
130+
pytest_args = ["--asyncio-mode=strict"]
131+
if sys.version_info >= (3, 14):
132+
pytest_args.extend(["-W", "default"])
133+
result = pytester.runpytest(*pytest_args)
134+
if sys.version_info >= (3, 14):
135+
result.assert_outcomes(passed=2, warnings=2)
136+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
137+
else:
138+
result.assert_outcomes(passed=2)
124139

125140

126141
def test_asyncio_mark_provides_module_scoped_loop_to_fixtures(

tests/markers/test_package_scope.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from textwrap import dedent
45

56
from pytest import Pytester
@@ -127,8 +128,15 @@ async def test_also_uses_custom_event_loop_policy():
127128
"""
128129
),
129130
)
130-
result = pytester.runpytest("--asyncio-mode=strict")
131-
result.assert_outcomes(passed=2)
131+
pytest_args = ["--asyncio-mode=strict"]
132+
if sys.version_info >= (3, 14):
133+
pytest_args.extend(["-W", "default"])
134+
result = pytester.runpytest(*pytest_args)
135+
if sys.version_info >= (3, 14):
136+
result.assert_outcomes(passed=2, warnings=3)
137+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
138+
else:
139+
result.assert_outcomes(passed=2)
132140

133141

134142
def test_asyncio_mark_respects_parametrized_loop_policies(
@@ -160,8 +168,15 @@ async def test_parametrized_loop():
160168
"""
161169
),
162170
)
163-
result = pytester.runpytest("--asyncio-mode=strict")
164-
result.assert_outcomes(passed=2)
171+
pytest_args = ["--asyncio-mode=strict"]
172+
if sys.version_info >= (3, 14):
173+
pytest_args.extend(["-W", "default"])
174+
result = pytester.runpytest(*pytest_args)
175+
if sys.version_info >= (3, 14):
176+
result.assert_outcomes(passed=2, warnings=2)
177+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
178+
else:
179+
result.assert_outcomes(passed=2)
165180

166181

167182
def test_asyncio_mark_provides_package_scoped_loop_to_fixtures(

tests/markers/test_session_scope.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from textwrap import dedent
45

56
from pytest import Pytester
@@ -128,8 +129,15 @@ async def test_also_uses_custom_event_loop_policy():
128129
"""
129130
),
130131
)
131-
result = pytester.runpytest("--asyncio-mode=strict")
132-
result.assert_outcomes(passed=2)
132+
pytest_args = ["--asyncio-mode=strict"]
133+
if sys.version_info >= (3, 14):
134+
pytest_args.extend(["-W", "default"])
135+
result = pytester.runpytest(*pytest_args)
136+
if sys.version_info >= (3, 14):
137+
result.assert_outcomes(passed=2, warnings=3)
138+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
139+
else:
140+
result.assert_outcomes(passed=2)
133141

134142

135143
def test_asyncio_mark_respects_parametrized_loop_policies(
@@ -161,8 +169,15 @@ async def test_parametrized_loop():
161169
"""
162170
),
163171
)
164-
result = pytester.runpytest("--asyncio-mode=strict")
165-
result.assert_outcomes(passed=2)
172+
pytest_args = ["--asyncio-mode=strict"]
173+
if sys.version_info >= (3, 14):
174+
pytest_args.extend(["-W", "default"])
175+
result = pytester.runpytest(*pytest_args)
176+
if sys.version_info >= (3, 14):
177+
result.assert_outcomes(passed=2, warnings=2)
178+
result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*")
179+
else:
180+
result.assert_outcomes(passed=2)
166181

167182

168183
def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(

0 commit comments

Comments
 (0)