55
66def test_asyncio_mark_provides_session_scoped_loop_strict_mode (pytester : Pytester ):
77 package_name = pytester .path .name
8+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
89 pytester .makepyfile (
910 __init__ = "" ,
1011 shared_module = dedent (
@@ -70,6 +71,7 @@ async def test_subpackage_runs_in_same_loop():
7071def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop (
7172 pytester : Pytester ,
7273):
74+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
7375 pytester .makepyfile (
7476 __init__ = "" ,
7577 test_raises = dedent (
@@ -91,6 +93,7 @@ async def test_remember_loop(event_loop):
9193def test_asyncio_mark_respects_the_loop_policy (
9294 pytester : Pytester ,
9395):
96+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
9497 pytester .makepyfile (
9598 __init__ = "" ,
9699 conftest = dedent (
@@ -152,6 +155,7 @@ async def test_also_uses_custom_event_loop_policy():
152155def test_asyncio_mark_respects_parametrized_loop_policies (
153156 pytester : Pytester ,
154157):
158+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
155159 pytester .makepyfile (
156160 __init__ = "" ,
157161 test_parametrization = dedent (
@@ -185,6 +189,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(
185189 pytester : Pytester ,
186190):
187191 package_name = pytester .path .name
192+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
188193 pytester .makepyfile (
189194 __init__ = "" ,
190195 conftest = dedent (
@@ -195,7 +200,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(
195200
196201 from { package_name } import shared_module
197202
198- @pytest_asyncio.fixture(scope="session")
203+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
199204 async def my_fixture():
200205 shared_module.loop = asyncio.get_running_loop()
201206 """
@@ -234,6 +239,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture):
234239def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scoped_test (
235240 pytester : Pytester ,
236241):
242+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
237243 pytester .makepyfile (
238244 __init__ = "" ,
239245 test_mixed_scopes = dedent (
@@ -245,7 +251,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scope
245251
246252 loop: asyncio.AbstractEventLoop
247253
248- @pytest_asyncio.fixture(scope="session")
254+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
249255 async def async_fixture():
250256 global loop
251257 loop = asyncio.get_running_loop()
@@ -264,6 +270,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
264270def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped_test (
265271 pytester : Pytester ,
266272):
273+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
267274 pytester .makepyfile (
268275 __init__ = "" ,
269276 test_mixed_scopes = dedent (
@@ -275,7 +282,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped
275282
276283 loop: asyncio.AbstractEventLoop
277284
278- @pytest_asyncio.fixture(scope="session")
285+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
279286 async def async_fixture():
280287 global loop
281288 loop = asyncio.get_running_loop()
@@ -294,6 +301,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
294301def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_test (
295302 pytester : Pytester ,
296303):
304+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
297305 pytester .makepyfile (
298306 __init__ = "" ,
299307 test_mixed_scopes = dedent (
@@ -305,7 +313,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_
305313
306314 loop: asyncio.AbstractEventLoop
307315
308- @pytest_asyncio.fixture(scope="session")
316+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
309317 async def async_fixture():
310318 global loop
311319 loop = asyncio.get_running_loop()
@@ -325,6 +333,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture):
325333def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scoped_test (
326334 pytester : Pytester ,
327335):
336+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
328337 pytester .makepyfile (
329338 __init__ = "" ,
330339 test_mixed_scopes = dedent (
@@ -336,7 +345,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scop
336345
337346 loop: asyncio.AbstractEventLoop
338347
339- @pytest_asyncio.fixture(scope="session")
348+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
340349 async def async_fixture():
341350 global loop
342351 loop = asyncio.get_running_loop()
@@ -355,6 +364,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
355364def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_test (
356365 pytester : Pytester ,
357366):
367+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
358368 pytester .makepyfile (
359369 __init__ = "" ,
360370 test_mixed_scopes = dedent (
@@ -366,7 +376,7 @@ def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_t
366376
367377 loop: asyncio.AbstractEventLoop
368378
369- @pytest_asyncio.fixture(scope="session")
379+ @pytest_asyncio.fixture(loop_scope="session", scope="session")
370380 async def async_fixture():
371381 global loop
372382 loop = asyncio.get_running_loop()
@@ -386,6 +396,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
386396def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture (
387397 pytester : Pytester ,
388398):
399+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
389400 pytester .makepyfile (
390401 dedent (
391402 """\
@@ -420,6 +431,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n):
420431def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set (
421432 pytester : Pytester ,
422433):
434+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
423435 pytester .makepyfile (
424436 dedent (
425437 """\
0 commit comments