5
5
6
6
def test_asyncio_mark_provides_session_scoped_loop_strict_mode (pytester : Pytester ):
7
7
package_name = pytester .path .name
8
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
8
9
pytester .makepyfile (
9
10
__init__ = "" ,
10
11
shared_module = dedent (
@@ -70,6 +71,7 @@ async def test_subpackage_runs_in_same_loop():
70
71
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop (
71
72
pytester : Pytester ,
72
73
):
74
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
73
75
pytester .makepyfile (
74
76
__init__ = "" ,
75
77
test_raises = dedent (
@@ -91,6 +93,7 @@ async def test_remember_loop(event_loop):
91
93
def test_asyncio_mark_respects_the_loop_policy (
92
94
pytester : Pytester ,
93
95
):
96
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
94
97
pytester .makepyfile (
95
98
__init__ = "" ,
96
99
conftest = dedent (
@@ -152,6 +155,7 @@ async def test_also_uses_custom_event_loop_policy():
152
155
def test_asyncio_mark_respects_parametrized_loop_policies (
153
156
pytester : Pytester ,
154
157
):
158
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
155
159
pytester .makepyfile (
156
160
__init__ = "" ,
157
161
test_parametrization = dedent (
@@ -185,6 +189,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(
185
189
pytester : Pytester ,
186
190
):
187
191
package_name = pytester .path .name
192
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
188
193
pytester .makepyfile (
189
194
__init__ = "" ,
190
195
conftest = dedent (
@@ -195,7 +200,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(
195
200
196
201
from { package_name } import shared_module
197
202
198
- @pytest_asyncio.fixture(scope="session")
203
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
199
204
async def my_fixture():
200
205
shared_module.loop = asyncio.get_running_loop()
201
206
"""
@@ -234,6 +239,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture):
234
239
def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scoped_test (
235
240
pytester : Pytester ,
236
241
):
242
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
237
243
pytester .makepyfile (
238
244
__init__ = "" ,
239
245
test_mixed_scopes = dedent (
@@ -245,7 +251,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scope
245
251
246
252
loop: asyncio.AbstractEventLoop
247
253
248
- @pytest_asyncio.fixture(scope="session")
254
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
249
255
async def async_fixture():
250
256
global loop
251
257
loop = asyncio.get_running_loop()
@@ -264,6 +270,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
264
270
def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped_test (
265
271
pytester : Pytester ,
266
272
):
273
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
267
274
pytester .makepyfile (
268
275
__init__ = "" ,
269
276
test_mixed_scopes = dedent (
@@ -275,7 +282,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped
275
282
276
283
loop: asyncio.AbstractEventLoop
277
284
278
- @pytest_asyncio.fixture(scope="session")
285
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
279
286
async def async_fixture():
280
287
global loop
281
288
loop = asyncio.get_running_loop()
@@ -294,6 +301,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
294
301
def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_test (
295
302
pytester : Pytester ,
296
303
):
304
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
297
305
pytester .makepyfile (
298
306
__init__ = "" ,
299
307
test_mixed_scopes = dedent (
@@ -305,7 +313,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_
305
313
306
314
loop: asyncio.AbstractEventLoop
307
315
308
- @pytest_asyncio.fixture(scope="session")
316
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
309
317
async def async_fixture():
310
318
global loop
311
319
loop = asyncio.get_running_loop()
@@ -325,6 +333,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture):
325
333
def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scoped_test (
326
334
pytester : Pytester ,
327
335
):
336
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
328
337
pytester .makepyfile (
329
338
__init__ = "" ,
330
339
test_mixed_scopes = dedent (
@@ -336,7 +345,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scop
336
345
337
346
loop: asyncio.AbstractEventLoop
338
347
339
- @pytest_asyncio.fixture(scope="session")
348
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
340
349
async def async_fixture():
341
350
global loop
342
351
loop = asyncio.get_running_loop()
@@ -355,6 +364,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
355
364
def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_test (
356
365
pytester : Pytester ,
357
366
):
367
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
358
368
pytester .makepyfile (
359
369
__init__ = "" ,
360
370
test_mixed_scopes = dedent (
@@ -366,7 +376,7 @@ def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_t
366
376
367
377
loop: asyncio.AbstractEventLoop
368
378
369
- @pytest_asyncio.fixture(scope="session")
379
+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
370
380
async def async_fixture():
371
381
global loop
372
382
loop = asyncio.get_running_loop()
@@ -386,6 +396,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
386
396
def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture (
387
397
pytester : Pytester ,
388
398
):
399
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
389
400
pytester .makepyfile (
390
401
dedent (
391
402
"""\
@@ -420,6 +431,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n):
420
431
def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set (
421
432
pytester : Pytester ,
422
433
):
434
+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
423
435
pytester .makepyfile (
424
436
dedent (
425
437
"""\
0 commit comments