Skip to content

Commit d688f7a

Browse files
committed
refactor: Addressed warnings about missing default fixture loop scope in tests/markers/test_package_scope.py.
1 parent 1f75ca7 commit d688f7a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/markers/test_package_scope.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
def test_asyncio_mark_provides_package_scoped_loop_strict_mode(pytester: Pytester):
77
package_name = pytester.path.name
88
subpackage_name = "subpkg"
9+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
910
pytester.makepyfile(
1011
__init__="",
1112
shared_module=dedent(
@@ -69,6 +70,7 @@ async def test_subpackage_runs_in_different_loop():
6970
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop(
7071
pytester: Pytester,
7172
):
73+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
7274
pytester.makepyfile(
7375
__init__="",
7476
test_raises=dedent(
@@ -90,6 +92,7 @@ async def test_remember_loop(event_loop):
9092
def test_asyncio_mark_respects_the_loop_policy(
9193
pytester: Pytester,
9294
):
95+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
9396
pytester.makepyfile(
9497
__init__="",
9598
conftest=dedent(
@@ -151,6 +154,7 @@ async def test_also_uses_custom_event_loop_policy():
151154
def test_asyncio_mark_respects_parametrized_loop_policies(
152155
pytester: Pytester,
153156
):
157+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
154158
pytester.makepyfile(
155159
__init__="",
156160
test_parametrization=dedent(
@@ -183,6 +187,7 @@ async def test_parametrized_loop():
183187
def test_asyncio_mark_provides_package_scoped_loop_to_fixtures(
184188
pytester: Pytester,
185189
):
190+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
186191
package_name = pytester.path.name
187192
pytester.makepyfile(
188193
__init__="",
@@ -194,7 +199,7 @@ def test_asyncio_mark_provides_package_scoped_loop_to_fixtures(
194199
195200
from {package_name} import shared_module
196201
197-
@pytest_asyncio.fixture(scope="package")
202+
@pytest_asyncio.fixture(loop_scope="package", scope="package")
198203
async def my_fixture():
199204
shared_module.loop = asyncio.get_running_loop()
200205
"""
@@ -229,6 +234,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture):
229234
def test_asyncio_mark_allows_combining_package_scoped_fixture_with_module_scoped_test(
230235
pytester: Pytester,
231236
):
237+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
232238
pytester.makepyfile(
233239
__init__="",
234240
test_mixed_scopes=dedent(
@@ -240,7 +246,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_module_scoped
240246
241247
loop: asyncio.AbstractEventLoop
242248
243-
@pytest_asyncio.fixture(scope="package")
249+
@pytest_asyncio.fixture(loop_scope="package", scope="package")
244250
async def async_fixture():
245251
global loop
246252
loop = asyncio.get_running_loop()
@@ -259,6 +265,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
259265
def test_asyncio_mark_allows_combining_package_scoped_fixture_with_class_scoped_test(
260266
pytester: Pytester,
261267
):
268+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
262269
pytester.makepyfile(
263270
__init__="",
264271
test_mixed_scopes=dedent(
@@ -270,7 +277,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_class_scoped_
270277
271278
loop: asyncio.AbstractEventLoop
272279
273-
@pytest_asyncio.fixture(scope="package")
280+
@pytest_asyncio.fixture(loop_scope="package", scope="package")
274281
async def async_fixture():
275282
global loop
276283
loop = asyncio.get_running_loop()
@@ -290,6 +297,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture):
290297
def test_asyncio_mark_allows_combining_package_scoped_fixture_with_function_scoped_test(
291298
pytester: Pytester,
292299
):
300+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
293301
pytester.makepyfile(
294302
__init__="",
295303
test_mixed_scopes=dedent(
@@ -301,7 +309,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_function_scop
301309
302310
loop: asyncio.AbstractEventLoop
303311
304-
@pytest_asyncio.fixture(scope="package")
312+
@pytest_asyncio.fixture(loop_scope="package", scope="package")
305313
async def async_fixture():
306314
global loop
307315
loop = asyncio.get_running_loop()
@@ -320,6 +328,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
320328
def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture(
321329
pytester: Pytester,
322330
):
331+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
323332
pytester.makepyfile(
324333
__init__="",
325334
test_loop_is_none=dedent(
@@ -355,6 +364,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n):
355364
def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set(
356365
pytester: Pytester,
357366
):
367+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
358368
pytester.makepyfile(
359369
__init__="",
360370
test_module=dedent(

0 commit comments

Comments
 (0)