Skip to content

Commit 502bd90

Browse files
committed
[test] Add explcitit warning filter to tests that expect warnings.
This avoids failing tests when running the tests with "python -m pytest" and installing a warning filter on the interpreter level. This can be useful for running tests in development mode, i.e. "python -Xdev -m pytest". Signed-off-by: Michael Seifert <[email protected]>
1 parent 50a2339 commit 502bd90

5 files changed

+19
-13
lines changed

tests/markers/test_function_scope.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def test_remember_loop(event_loop):
4343
"""
4444
)
4545
)
46-
result = pytester.runpytest("--asyncio-mode=strict")
46+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
4747
result.assert_outcomes(passed=1, warnings=1)
4848
result.stdout.fnmatch_lines(
4949
'*is asynchronous and explicitly requests the "event_loop" fixture*'

tests/markers/test_module_scope.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ def sample_fixture():
4848
"""
4949
)
5050
)
51-
result = pytester.runpytest("--asyncio-mode=strict")
52-
result.assert_outcomes(passed=2)
51+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
52+
result.assert_outcomes(passed=2, warnings=2)
53+
result.stdout.fnmatch_lines(
54+
'*is asynchronous and explicitly requests the "event_loop" fixture*'
55+
)
5356

5457

5558
def test_asyncio_mark_provides_module_scoped_loop_strict_mode(pytester: Pytester):

tests/test_event_loop_fixture_finalizer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ async def test_async_with_explicit_fixture_request(event_loop):
8484
"""
8585
)
8686
)
87-
result = pytester.runpytest("--asyncio-mode=strict")
88-
result.assert_outcomes(passed=1)
87+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
88+
result.assert_outcomes(passed=1, warnings=1)
89+
result.stdout.fnmatch_lines(
90+
'*is asynchronous and explicitly requests the "event_loop" fixture*'
91+
)
8992

9093

9194
def test_event_loop_fixture_finalizer_raises_warning_when_fixture_leaves_loop_unclosed(

tests/test_event_loop_fixture_override_deprecation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def test_emits_warning():
2222
"""
2323
)
2424
)
25-
result = pytester.runpytest("--asyncio-mode=strict")
25+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
2626
result.assert_outcomes(passed=1, warnings=1)
2727
result.stdout.fnmatch_lines(
2828
["*event_loop fixture provided by pytest-asyncio has been redefined*"]
@@ -50,7 +50,7 @@ async def test_emits_warning_when_requested_explicitly(event_loop):
5050
"""
5151
)
5252
)
53-
result = pytester.runpytest("--asyncio-mode=strict")
53+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
5454
result.assert_outcomes(passed=1, warnings=2)
5555
result.stdout.fnmatch_lines(
5656
["*event_loop fixture provided by pytest-asyncio has been redefined*"]
@@ -107,5 +107,5 @@ def test_emits_warning(uses_event_loop):
107107
"""
108108
)
109109
)
110-
result = pytester.runpytest("--asyncio-mode=strict")
110+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
111111
result.assert_outcomes(passed=1, warnings=1)

tests/test_explicit_event_loop_fixture_request.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def test_coroutine_emits_warning(event_loop):
1717
"""
1818
)
1919
)
20-
result = pytester.runpytest("--asyncio-mode=strict")
20+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
2121
result.assert_outcomes(passed=1, warnings=1)
2222
result.stdout.fnmatch_lines(
2323
['*is asynchronous and explicitly requests the "event_loop" fixture*']
@@ -39,7 +39,7 @@ async def test_coroutine_emits_warning(self, event_loop):
3939
"""
4040
)
4141
)
42-
result = pytester.runpytest("--asyncio-mode=strict")
42+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
4343
result.assert_outcomes(passed=1, warnings=1)
4444
result.stdout.fnmatch_lines(
4545
['*is asynchronous and explicitly requests the "event_loop" fixture*']
@@ -62,7 +62,7 @@ async def test_coroutine_emits_warning(event_loop):
6262
"""
6363
)
6464
)
65-
result = pytester.runpytest("--asyncio-mode=strict")
65+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
6666
result.assert_outcomes(passed=1, warnings=1)
6767
result.stdout.fnmatch_lines(
6868
['*is asynchronous and explicitly requests the "event_loop" fixture*']
@@ -88,7 +88,7 @@ async def test_uses_fixture(emits_warning):
8888
"""
8989
)
9090
)
91-
result = pytester.runpytest("--asyncio-mode=strict")
91+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
9292
result.assert_outcomes(passed=1, warnings=1)
9393
result.stdout.fnmatch_lines(
9494
['*is asynchronous and explicitly requests the "event_loop" fixture*']
@@ -114,7 +114,7 @@ async def test_uses_fixture(emits_warning):
114114
"""
115115
)
116116
)
117-
result = pytester.runpytest("--asyncio-mode=strict")
117+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
118118
result.assert_outcomes(passed=1, warnings=1)
119119
result.stdout.fnmatch_lines(
120120
['*is asynchronous and explicitly requests the "event_loop" fixture*']

0 commit comments

Comments
 (0)