Skip to content

Commit e354c5c

Browse files
committedMay 4, 2021
Fix warning filters used in tests
1 parent 7104464 commit e354c5c

7 files changed

+27
-27
lines changed
 

‎testing/acceptance_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ def test_usage_error_code(pytester: Pytester) -> None:
11731173
assert result.ret == ExitCode.USAGE_ERROR
11741174

11751175

1176-
@pytest.mark.filterwarnings("default")
1176+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
11771177
def test_warn_on_async_function(pytester: Pytester) -> None:
11781178
# In the below we .close() the coroutine only to avoid
11791179
# "RuntimeWarning: coroutine 'test_2' was never awaited"
@@ -1206,7 +1206,7 @@ def test_3():
12061206
)
12071207

12081208

1209-
@pytest.mark.filterwarnings("default")
1209+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
12101210
def test_warn_on_async_gen_function(pytester: Pytester) -> None:
12111211
pytester.makepyfile(
12121212
test_async="""

‎testing/python/collect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ class Test(object):
12371237
assert result.ret == ExitCode.NO_TESTS_COLLECTED
12381238

12391239

1240-
@pytest.mark.filterwarnings("default")
1240+
@pytest.mark.filterwarnings("default::pytest.PytestCollectionWarning")
12411241
def test_dont_collect_non_function_callable(pytester: Pytester) -> None:
12421242
"""Test for issue https://github.com/pytest-dev/pytest/issues/331
12431243

‎testing/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def test_silence_unknown_key_warning(self, pytester: Pytester) -> None:
290290
result = pytester.runpytest()
291291
result.stdout.no_fnmatch_line("*PytestConfigWarning*")
292292

293-
@pytest.mark.filterwarnings("default")
293+
@pytest.mark.filterwarnings("default::pytest.PytestConfigWarning")
294294
def test_disable_warnings_plugin_disables_config_warnings(
295295
self, pytester: Pytester
296296
) -> None:

‎testing/test_terminal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
16181618
)
16191619

16201620

1621-
@pytest.mark.filterwarnings("default")
1621+
@pytest.mark.filterwarnings("default::UserWarning")
16221622
def test_terminal_summary_warnings_are_displayed(pytester: Pytester) -> None:
16231623
"""Test that warnings emitted during pytest_terminal_summary are displayed.
16241624
(#1305).
@@ -1655,7 +1655,7 @@ def test_failure():
16551655
assert stdout.count("=== warnings summary ") == 2
16561656

16571657

1658-
@pytest.mark.filterwarnings("default")
1658+
@pytest.mark.filterwarnings("default::UserWarning")
16591659
def test_terminal_summary_warnings_header_once(pytester: Pytester) -> None:
16601660
pytester.makepyfile(
16611661
"""

‎testing/test_threadexception.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytest.skip("threadexception plugin needs Python>=3.8", allow_module_level=True)
99

1010

11-
@pytest.mark.filterwarnings("default")
11+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
1212
def test_unhandled_thread_exception(pytester: Pytester) -> None:
1313
pytester.makepyfile(
1414
test_it="""
@@ -42,7 +42,7 @@ def test_2(): pass
4242
)
4343

4444

45-
@pytest.mark.filterwarnings("default")
45+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
4646
def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None:
4747
pytester.makepyfile(
4848
test_it="""
@@ -78,7 +78,7 @@ def test_2(): pass
7878
)
7979

8080

81-
@pytest.mark.filterwarnings("default")
81+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
8282
def test_unhandled_thread_exception_in_teardown(pytester: Pytester) -> None:
8383
pytester.makepyfile(
8484
test_it="""

‎testing/test_unraisableexception.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytest.skip("unraisableexception plugin needs Python>=3.8", allow_module_level=True)
99

1010

11-
@pytest.mark.filterwarnings("default")
11+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
1212
def test_unraisable(pytester: Pytester) -> None:
1313
pytester.makepyfile(
1414
test_it="""
@@ -40,7 +40,7 @@ def test_2(): pass
4040
)
4141

4242

43-
@pytest.mark.filterwarnings("default")
43+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
4444
def test_unraisable_in_setup(pytester: Pytester) -> None:
4545
pytester.makepyfile(
4646
test_it="""
@@ -76,7 +76,7 @@ def test_2(): pass
7676
)
7777

7878

79-
@pytest.mark.filterwarnings("default")
79+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
8080
def test_unraisable_in_teardown(pytester: Pytester) -> None:
8181
pytester.makepyfile(
8282
test_it="""

‎testing/test_warnings.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def foo():
3838
return str(test_file)
3939

4040

41-
@pytest.mark.filterwarnings("default")
41+
@pytest.mark.filterwarnings("default::UserWarning", "default::RuntimeWarning")
4242
def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None:
4343
"""Check that the warnings section is displayed."""
4444
result = pytester.runpytest(pyfile_with_warnings)
@@ -55,7 +55,7 @@ def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None:
5555
)
5656

5757

58-
@pytest.mark.filterwarnings("always")
58+
@pytest.mark.filterwarnings("always::UserWarning")
5959
def test_setup_teardown_warnings(pytester: Pytester) -> None:
6060
pytester.makepyfile(
6161
"""
@@ -123,7 +123,7 @@ def test_ignore(pytester: Pytester, pyfile_with_warnings, method) -> None:
123123
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
124124

125125

126-
@pytest.mark.filterwarnings("always")
126+
@pytest.mark.filterwarnings("always::UserWarning")
127127
def test_unicode(pytester: Pytester) -> None:
128128
pytester.makepyfile(
129129
"""
@@ -182,7 +182,7 @@ def test_filterwarnings_mark(pytester: Pytester, default_config) -> None:
182182
pytester.makeini(
183183
"""
184184
[pytest]
185-
filterwarnings = always
185+
filterwarnings = always::RuntimeWarning
186186
"""
187187
)
188188
pytester.makepyfile(
@@ -202,7 +202,9 @@ def test_show_warning():
202202
warnings.warn(RuntimeWarning())
203203
"""
204204
)
205-
result = pytester.runpytest("-W always" if default_config == "cmdline" else "")
205+
result = pytester.runpytest(
206+
"-W always::RuntimeWarning" if default_config == "cmdline" else ""
207+
)
206208
result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warning in *"])
207209

208210

@@ -217,7 +219,7 @@ def test():
217219
warnings.warn(UserWarning(1, 'foo'))
218220
"""
219221
)
220-
result = pytester.runpytest("-W", "always")
222+
result = pytester.runpytest("-W", "always::UserWarning")
221223
result.stdout.fnmatch_lines(["*= 1 passed, 1 warning in *"])
222224

223225

@@ -236,7 +238,7 @@ def test_func():
236238
assert result.ret == 0
237239

238240

239-
@pytest.mark.filterwarnings("always")
241+
@pytest.mark.filterwarnings("always::UserWarning")
240242
def test_warning_captured_hook(pytester: Pytester) -> None:
241243
pytester.makeconftest(
242244
"""
@@ -297,7 +299,7 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
297299
assert collected_result[3] is None, str(collected)
298300

299301

300-
@pytest.mark.filterwarnings("always")
302+
@pytest.mark.filterwarnings("always::UserWarning")
301303
def test_collection_warnings(pytester: Pytester) -> None:
302304
"""Check that we also capture warnings issued during test collection (#3251)."""
303305
pytester.makepyfile(
@@ -321,7 +323,7 @@ def test_foo():
321323
)
322324

323325

324-
@pytest.mark.filterwarnings("always")
326+
@pytest.mark.filterwarnings("always::UserWarning")
325327
def test_mark_regex_escape(pytester: Pytester) -> None:
326328
"""@pytest.mark.filterwarnings should not try to escape regex characters (#3936)"""
327329
pytester.makepyfile(
@@ -337,7 +339,7 @@ def test_foo():
337339
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
338340

339341

340-
@pytest.mark.filterwarnings("default")
342+
@pytest.mark.filterwarnings("default::pytest.PytestWarning")
341343
@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
342344
def test_hide_pytest_internal_warnings(
343345
pytester: Pytester, ignore_pytest_warnings
@@ -387,7 +389,7 @@ def test_option_precedence_cmdline_over_ini(
387389
pytester.makeini(
388390
"""
389391
[pytest]
390-
filterwarnings = error
392+
filterwarnings = error::UserWarning
391393
"""
392394
)
393395
pytester.makepyfile(
@@ -581,8 +583,7 @@ def test_warnings_checker_twice() -> None:
581583
warnings.warn("Message B", UserWarning)
582584

583585

584-
@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
585-
@pytest.mark.filterwarnings("always")
586+
@pytest.mark.filterwarnings("always::UserWarning")
586587
def test_group_warnings_by_message(pytester: Pytester) -> None:
587588
pytester.copy_example("warnings/test_group_warnings_by_message.py")
588589
result = pytester.runpytest()
@@ -613,8 +614,7 @@ def test_group_warnings_by_message(pytester: Pytester) -> None:
613614
)
614615

615616

616-
@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
617-
@pytest.mark.filterwarnings("always")
617+
@pytest.mark.filterwarnings("always::UserWarning")
618618
def test_group_warnings_by_message_summary(pytester: Pytester) -> None:
619619
pytester.copy_example("warnings/test_group_warnings_by_message_summary")
620620
pytester.syspathinsert()

0 commit comments

Comments
 (0)
Please sign in to comment.