Skip to content

Commit 22fa51c

Browse files
fix(tests): replace runpytest_subprocess with runpytest
- runpytest_subprocess uses system-installed pytest-asyncio instead of development version, causing typeerror when tests needs to use loop_scope parameter
1 parent 7069b5b commit 22fa51c

12 files changed

+42
-41
lines changed

changelog.d/1275.downstream.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests are run in the same pytest process, instead of spawning a subprocess with `pytest.Pytester.runpytest_subprocess`. This prevents the test suite from accidentally using a system installation of pytest-asyncio, which could result in test errors.

tests/hypothesis/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def test_mark_inner(n):
2727
"""
2828
)
2929
)
30-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
30+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
3131
result.assert_outcomes(passed=1)
3232

3333

tests/markers/test_class_scope.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def test_parametrized_loop(self, request):
175175
"""
176176
)
177177
)
178-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
178+
result = pytester.runpytest("--asyncio-mode=strict")
179179
result.assert_outcomes(passed=2)
180180

181181

@@ -205,7 +205,7 @@ async def test_runs_is_same_loop_as_fixture(self, my_fixture):
205205
"""
206206
)
207207
)
208-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
208+
result = pytester.runpytest("--asyncio-mode=strict")
209209
result.assert_outcomes(passed=1)
210210

211211

@@ -293,5 +293,5 @@ async def test_anything(self):
293293
"""
294294
)
295295
)
296-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
296+
result = pytester.runpytest("--asyncio-mode=strict")
297297
result.assert_outcomes(warnings=0, passed=1)

tests/markers/test_invalid_arguments.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def test_anything():
1919
"""
2020
)
2121
)
22-
result = pytester.runpytest_subprocess()
22+
result = pytester.runpytest("--assert=plain")
2323
result.assert_outcomes(passed=1)
2424
result.stdout.no_fnmatch_line("*ValueError*")
2525

@@ -38,7 +38,7 @@ async def test_anything():
3838
"""
3939
)
4040
)
41-
result = pytester.runpytest_subprocess()
41+
result = pytester.runpytest("--assert=plain")
4242
result.assert_outcomes(errors=1)
4343
result.stdout.fnmatch_lines(
4444
["*ValueError: mark.asyncio accepts only a keyword argument*"]
@@ -59,7 +59,7 @@ async def test_anything():
5959
"""
6060
)
6161
)
62-
result = pytester.runpytest_subprocess()
62+
result = pytester.runpytest("--assert=plain")
6363
result.assert_outcomes(errors=1)
6464
result.stdout.fnmatch_lines(
6565
["*ValueError: mark.asyncio accepts only a keyword argument 'loop_scope'*"]
@@ -80,7 +80,7 @@ async def test_anything():
8080
"""
8181
)
8282
)
83-
result = pytester.runpytest_subprocess()
83+
result = pytester.runpytest("--assert=plain")
8484
result.assert_outcomes(errors=1)
8585
result.stdout.fnmatch_lines(
8686
["*ValueError: mark.asyncio accepts only a keyword argument*"]

tests/markers/test_module_scope.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def test_parametrized_loop():
119119
"""
120120
)
121121
)
122-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
122+
result = pytester.runpytest("--asyncio-mode=strict")
123123
result.assert_outcomes(passed=2)
124124

125125

@@ -150,7 +150,7 @@ async def test_runs_is_same_loop_as_fixture(my_fixture):
150150
"""
151151
)
152152
)
153-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
153+
result = pytester.runpytest("--asyncio-mode=strict")
154154
result.assert_outcomes(passed=1)
155155

156156

@@ -298,5 +298,5 @@ async def test_anything():
298298
"""
299299
)
300300
)
301-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
301+
result = pytester.runpytest("--asyncio-mode=strict")
302302
result.assert_outcomes(warnings=0, passed=1)

tests/markers/test_package_scope.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def test_parametrized_loop():
160160
"""
161161
),
162162
)
163-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
163+
result = pytester.runpytest("--asyncio-mode=strict")
164164
result.assert_outcomes(passed=2)
165165

166166

@@ -207,7 +207,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture):
207207
"""
208208
),
209209
)
210-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
210+
result = pytester.runpytest("--asyncio-mode=strict")
211211
result.assert_outcomes(passed=1)
212212

213213

tests/markers/test_session_scope.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def test_parametrized_loop():
161161
"""
162162
),
163163
)
164-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
164+
result = pytester.runpytest("--asyncio-mode=strict")
165165
result.assert_outcomes(passed=2)
166166

167167

@@ -212,7 +212,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture):
212212
"""
213213
)
214214
)
215-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
215+
result = pytester.runpytest("--asyncio-mode=strict")
216216
result.assert_outcomes(passed=1)
217217

218218

@@ -423,5 +423,5 @@ async def test_anything():
423423
"""
424424
)
425425
)
426-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
426+
result = pytester.runpytest("--asyncio-mode=strict")
427427
result.assert_outcomes(warnings=0, passed=1)

tests/modes/test_strict_mode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def test_anything():
9494
"""
9595
)
9696
)
97-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
97+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
9898
if pytest_version >= (8, 4, 0):
9999
result.assert_outcomes(failed=1, skipped=0, warnings=0)
100100
else:
@@ -119,7 +119,7 @@ async def test_anything(any_fixture):
119119
"""
120120
)
121121
)
122-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
122+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
123123

124124
if pytest_version >= (8, 4, 0):
125125
result.assert_outcomes(failed=1, skipped=0, warnings=2)
@@ -155,7 +155,7 @@ async def test_anything(any_fixture):
155155
"""
156156
)
157157
)
158-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
158+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
159159
if pytest_version >= (8, 4, 0):
160160
result.assert_outcomes(passed=1, failed=0, skipped=0, warnings=2)
161161
else:
@@ -202,7 +202,7 @@ async def test_anything(any_fixture):
202202
"""
203203
)
204204
)
205-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
205+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
206206
if pytest_version >= (8, 4, 0):
207207
result.assert_outcomes(passed=1, warnings=2)
208208
else:

tests/test_asyncio_mark.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_a():
1717
"""
1818
)
1919
)
20-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
20+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
2121
result.assert_outcomes(passed=1)
2222
result.stdout.fnmatch_lines(
2323
["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"]
@@ -38,7 +38,7 @@ async def test_a():
3838
"""
3939
)
4040
)
41-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
41+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
4242
result.assert_outcomes(xfailed=1, warnings=1)
4343
result.stdout.fnmatch_lines(
4444
["*Tests based on asynchronous generators are not supported*"]
@@ -56,7 +56,7 @@ async def test_a():
5656
"""
5757
)
5858
)
59-
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
59+
result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain")
6060
result.assert_outcomes(xfailed=1, warnings=1)
6161
result.stdout.fnmatch_lines(
6262
["*Tests based on asynchronous generators are not supported*"]
@@ -78,7 +78,7 @@ async def test_a(self):
7878
"""
7979
)
8080
)
81-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
81+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
8282
result.assert_outcomes(xfailed=1, warnings=1)
8383
result.stdout.fnmatch_lines(
8484
["*Tests based on asynchronous generators are not supported*"]
@@ -98,7 +98,7 @@ async def test_a():
9898
"""
9999
)
100100
)
101-
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
101+
result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain")
102102
result.assert_outcomes(xfailed=1, warnings=1)
103103
result.stdout.fnmatch_lines(
104104
["*Tests based on asynchronous generators are not supported*"]
@@ -121,7 +121,7 @@ async def test_a():
121121
"""
122122
)
123123
)
124-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
124+
result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain")
125125
result.assert_outcomes(xfailed=1, warnings=1)
126126
result.stdout.fnmatch_lines(
127127
["*Tests based on asynchronous generators are not supported*"]
@@ -141,7 +141,7 @@ async def test_a():
141141
"""
142142
)
143143
)
144-
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
144+
result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain")
145145
result.assert_outcomes(xfailed=1, warnings=1)
146146
result.stdout.fnmatch_lines(
147147
["*Tests based on asynchronous generators are not supported*"]

tests/test_event_loop_fixture.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def test_custom_policy_is_not_overwritten():
5151
"""
5252
)
5353
)
54-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
54+
result = pytester.runpytest("--asyncio-mode=strict")
5555
result.assert_outcomes(passed=2)
5656

5757

@@ -78,7 +78,7 @@ async def generator_fn():
7878
"""
7979
)
8080
)
81-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
81+
result = pytester.runpytest("--asyncio-mode=strict", "-W", "default")
8282
result.assert_outcomes(passed=1, warnings=0)
8383

8484

@@ -110,7 +110,7 @@ async def test_something(close_event_loop):
110110
"""
111111
)
112112
)
113-
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
113+
result = pytester.runpytest("--asyncio-mode=strict", "--assert=plain")
114114
result.assert_outcomes(passed=1, warnings=1)
115115
result.stdout.fnmatch_lines(
116116
["*An exception occurred during teardown of an asyncio.Runner*"]
@@ -139,5 +139,5 @@ async def fail():
139139
"""
140140
)
141141
)
142-
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
142+
result = pytester.runpytest("--asyncio-mode=strict", "-W", "default")
143143
result.assert_outcomes(passed=1, warnings=1)

0 commit comments

Comments
 (0)