Skip to content

Commit 1f75ca7

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

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/markers/test_module_scope.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
def test_asyncio_mark_works_on_module_level(pytester: Pytester):
7+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
78
pytester.makepyfile(
89
dedent(
910
"""\
@@ -56,6 +57,7 @@ def sample_fixture():
5657

5758

5859
def test_asyncio_mark_provides_module_scoped_loop_strict_mode(pytester: Pytester):
60+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
5961
pytester.makepyfile(
6062
dedent(
6163
"""\
@@ -88,6 +90,7 @@ async def test_this_runs_in_same_loop(self):
8890
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop(
8991
pytester: Pytester,
9092
):
93+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
9194
pytester.makepyfile(
9295
dedent(
9396
"""\
@@ -109,6 +112,7 @@ async def test_remember_loop(event_loop):
109112
def test_asyncio_mark_respects_the_loop_policy(
110113
pytester: Pytester,
111114
):
115+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
112116
pytester.makepyfile(
113117
__init__="",
114118
custom_policy=dedent(
@@ -163,6 +167,7 @@ async def test_does_not_use_custom_event_loop_policy():
163167
def test_asyncio_mark_respects_parametrized_loop_policies(
164168
pytester: Pytester,
165169
):
170+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
166171
pytester.makepyfile(
167172
dedent(
168173
"""\
@@ -194,6 +199,7 @@ async def test_parametrized_loop():
194199
def test_asyncio_mark_provides_module_scoped_loop_to_fixtures(
195200
pytester: Pytester,
196201
):
202+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
197203
pytester.makepyfile(
198204
dedent(
199205
"""\
@@ -206,7 +212,7 @@ def test_asyncio_mark_provides_module_scoped_loop_to_fixtures(
206212
207213
loop: asyncio.AbstractEventLoop
208214
209-
@pytest_asyncio.fixture(scope="module")
215+
@pytest_asyncio.fixture(loop_scope="module", scope="module")
210216
async def my_fixture():
211217
global loop
212218
loop = asyncio.get_running_loop()
@@ -224,6 +230,7 @@ async def test_runs_is_same_loop_as_fixture(my_fixture):
224230
def test_asyncio_mark_allows_combining_module_scoped_fixture_with_class_scoped_test(
225231
pytester: Pytester,
226232
):
233+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
227234
pytester.makepyfile(
228235
dedent(
229236
"""\
@@ -234,7 +241,7 @@ def test_asyncio_mark_allows_combining_module_scoped_fixture_with_class_scoped_t
234241
235242
loop: asyncio.AbstractEventLoop
236243
237-
@pytest_asyncio.fixture(scope="module")
244+
@pytest_asyncio.fixture(loop_scope="module", scope="module")
238245
async def async_fixture():
239246
global loop
240247
loop = asyncio.get_running_loop()
@@ -255,6 +262,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture):
255262
def test_asyncio_mark_allows_combining_module_scoped_fixture_with_function_scoped_test(
256263
pytester: Pytester,
257264
):
265+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
258266
pytester.makepyfile(
259267
__init__="",
260268
test_mixed_scopes=dedent(
@@ -266,7 +274,7 @@ def test_asyncio_mark_allows_combining_module_scoped_fixture_with_function_scope
266274
267275
loop: asyncio.AbstractEventLoop
268276
269-
@pytest_asyncio.fixture(scope="module")
277+
@pytest_asyncio.fixture(loop_scope="module", scope="module")
270278
async def async_fixture():
271279
global loop
272280
loop = asyncio.get_running_loop()
@@ -285,6 +293,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
285293
def test_allows_combining_module_scoped_asyncgen_fixture_with_function_scoped_test(
286294
pytester: Pytester,
287295
):
296+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
288297
pytester.makepyfile(
289298
dedent(
290299
"""\
@@ -295,7 +304,7 @@ def test_allows_combining_module_scoped_asyncgen_fixture_with_function_scoped_te
295304
296305
loop: asyncio.AbstractEventLoop
297306
298-
@pytest_asyncio.fixture(scope="module")
307+
@pytest_asyncio.fixture(loop_scope="module", scope="module")
299308
async def async_fixture():
300309
global loop
301310
loop = asyncio.get_running_loop()
@@ -315,6 +324,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture):
315324
def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture(
316325
pytester: Pytester,
317326
):
327+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
318328
pytester.makepyfile(
319329
dedent(
320330
"""\
@@ -349,6 +359,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n):
349359
def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set(
350360
pytester: Pytester,
351361
):
362+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
352363
pytester.makepyfile(
353364
dedent(
354365
"""\

0 commit comments

Comments
 (0)