Fix warning filters used in tests
This commit is contained in:
		
							parent
							
								
									710446420c
								
							
						
					
					
						commit
						e354c5c919
					
				|  | @ -1173,7 +1173,7 @@ def test_usage_error_code(pytester: Pytester) -> None: | ||||||
|     assert result.ret == ExitCode.USAGE_ERROR |     assert result.ret == ExitCode.USAGE_ERROR | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning") | ||||||
| def test_warn_on_async_function(pytester: Pytester) -> None: | def test_warn_on_async_function(pytester: Pytester) -> None: | ||||||
|     # In the below we .close() the coroutine only to avoid |     # In the below we .close() the coroutine only to avoid | ||||||
|     # "RuntimeWarning: coroutine 'test_2' was never awaited" |     # "RuntimeWarning: coroutine 'test_2' was never awaited" | ||||||
|  | @ -1206,7 +1206,7 @@ def test_warn_on_async_function(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning") | ||||||
| def test_warn_on_async_gen_function(pytester: Pytester) -> None: | def test_warn_on_async_gen_function(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_async=""" |         test_async=""" | ||||||
|  |  | ||||||
|  | @ -1237,7 +1237,7 @@ def test_unorderable_types(pytester: Pytester) -> None: | ||||||
|     assert result.ret == ExitCode.NO_TESTS_COLLECTED |     assert result.ret == ExitCode.NO_TESTS_COLLECTED | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestCollectionWarning") | ||||||
| def test_dont_collect_non_function_callable(pytester: Pytester) -> None: | def test_dont_collect_non_function_callable(pytester: Pytester) -> None: | ||||||
|     """Test for issue https://github.com/pytest-dev/pytest/issues/331 |     """Test for issue https://github.com/pytest-dev/pytest/issues/331 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -290,7 +290,7 @@ class TestParseIni: | ||||||
|         result = pytester.runpytest() |         result = pytester.runpytest() | ||||||
|         result.stdout.no_fnmatch_line("*PytestConfigWarning*") |         result.stdout.no_fnmatch_line("*PytestConfigWarning*") | ||||||
| 
 | 
 | ||||||
|     @pytest.mark.filterwarnings("default") |     @pytest.mark.filterwarnings("default::pytest.PytestConfigWarning") | ||||||
|     def test_disable_warnings_plugin_disables_config_warnings( |     def test_disable_warnings_plugin_disables_config_warnings( | ||||||
|         self, pytester: Pytester |         self, pytester: Pytester | ||||||
|     ) -> None: |     ) -> None: | ||||||
|  |  | ||||||
|  | @ -1618,7 +1618,7 @@ def test_terminal_summary(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::UserWarning") | ||||||
| def test_terminal_summary_warnings_are_displayed(pytester: Pytester) -> None: | def test_terminal_summary_warnings_are_displayed(pytester: Pytester) -> None: | ||||||
|     """Test that warnings emitted during pytest_terminal_summary are displayed. |     """Test that warnings emitted during pytest_terminal_summary are displayed. | ||||||
|     (#1305). |     (#1305). | ||||||
|  | @ -1655,7 +1655,7 @@ def test_terminal_summary_warnings_are_displayed(pytester: Pytester) -> None: | ||||||
|     assert stdout.count("=== warnings summary ") == 2 |     assert stdout.count("=== warnings summary ") == 2 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::UserWarning") | ||||||
| def test_terminal_summary_warnings_header_once(pytester: Pytester) -> None: | def test_terminal_summary_warnings_header_once(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ if sys.version_info < (3, 8): | ||||||
|     pytest.skip("threadexception plugin needs Python>=3.8", allow_module_level=True) |     pytest.skip("threadexception plugin needs Python>=3.8", allow_module_level=True) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning") | ||||||
| def test_unhandled_thread_exception(pytester: Pytester) -> None: | def test_unhandled_thread_exception(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  | @ -42,7 +42,7 @@ def test_unhandled_thread_exception(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning") | ||||||
| def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None: | def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  | @ -78,7 +78,7 @@ def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning") | ||||||
| def test_unhandled_thread_exception_in_teardown(pytester: Pytester) -> None: | def test_unhandled_thread_exception_in_teardown(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ if sys.version_info < (3, 8): | ||||||
|     pytest.skip("unraisableexception plugin needs Python>=3.8", allow_module_level=True) |     pytest.skip("unraisableexception plugin needs Python>=3.8", allow_module_level=True) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning") | ||||||
| def test_unraisable(pytester: Pytester) -> None: | def test_unraisable(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  | @ -40,7 +40,7 @@ def test_unraisable(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning") | ||||||
| def test_unraisable_in_setup(pytester: Pytester) -> None: | def test_unraisable_in_setup(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  | @ -76,7 +76,7 @@ def test_unraisable_in_setup(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning") | ||||||
| def test_unraisable_in_teardown(pytester: Pytester) -> None: | def test_unraisable_in_teardown(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         test_it=""" |         test_it=""" | ||||||
|  |  | ||||||
|  | @ -38,7 +38,7 @@ def pyfile_with_warnings(pytester: Pytester, request: FixtureRequest) -> str: | ||||||
|     return str(test_file) |     return str(test_file) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::UserWarning", "default::RuntimeWarning") | ||||||
| def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None: | def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None: | ||||||
|     """Check that the warnings section is displayed.""" |     """Check that the warnings section is displayed.""" | ||||||
|     result = pytester.runpytest(pyfile_with_warnings) |     result = pytester.runpytest(pyfile_with_warnings) | ||||||
|  | @ -55,7 +55,7 @@ def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("always") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| def test_setup_teardown_warnings(pytester: Pytester) -> None: | def test_setup_teardown_warnings(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         """ |         """ | ||||||
|  | @ -123,7 +123,7 @@ def test_ignore(pytester: Pytester, pyfile_with_warnings, method) -> None: | ||||||
|     assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() |     assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("always") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| def test_unicode(pytester: Pytester) -> None: | def test_unicode(pytester: Pytester) -> None: | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|         """ |         """ | ||||||
|  | @ -182,7 +182,7 @@ def test_filterwarnings_mark(pytester: Pytester, default_config) -> None: | ||||||
|         pytester.makeini( |         pytester.makeini( | ||||||
|             """ |             """ | ||||||
|             [pytest] |             [pytest] | ||||||
|             filterwarnings = always |             filterwarnings = always::RuntimeWarning | ||||||
|         """ |         """ | ||||||
|         ) |         ) | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|  | @ -202,7 +202,9 @@ def test_filterwarnings_mark(pytester: Pytester, default_config) -> None: | ||||||
|             warnings.warn(RuntimeWarning()) |             warnings.warn(RuntimeWarning()) | ||||||
|     """ |     """ | ||||||
|     ) |     ) | ||||||
|     result = pytester.runpytest("-W always" if default_config == "cmdline" else "") |     result = pytester.runpytest( | ||||||
|  |         "-W always::RuntimeWarning" if default_config == "cmdline" else "" | ||||||
|  |     ) | ||||||
|     result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warning in *"]) |     result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warning in *"]) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -217,7 +219,7 @@ def test_non_string_warning_argument(pytester: Pytester) -> None: | ||||||
|             warnings.warn(UserWarning(1, 'foo')) |             warnings.warn(UserWarning(1, 'foo')) | ||||||
|         """ |         """ | ||||||
|     ) |     ) | ||||||
|     result = pytester.runpytest("-W", "always") |     result = pytester.runpytest("-W", "always::UserWarning") | ||||||
|     result.stdout.fnmatch_lines(["*= 1 passed, 1 warning in *"]) |     result.stdout.fnmatch_lines(["*= 1 passed, 1 warning in *"]) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -236,7 +238,7 @@ def test_filterwarnings_mark_registration(pytester: Pytester) -> None: | ||||||
|     assert result.ret == 0 |     assert result.ret == 0 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("always") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| def test_warning_captured_hook(pytester: Pytester) -> None: | def test_warning_captured_hook(pytester: Pytester) -> None: | ||||||
|     pytester.makeconftest( |     pytester.makeconftest( | ||||||
|         """ |         """ | ||||||
|  | @ -297,7 +299,7 @@ def test_warning_captured_hook(pytester: Pytester) -> None: | ||||||
|             assert collected_result[3] is None, str(collected) |             assert collected_result[3] is None, str(collected) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("always") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| def test_collection_warnings(pytester: Pytester) -> None: | def test_collection_warnings(pytester: Pytester) -> None: | ||||||
|     """Check that we also capture warnings issued during test collection (#3251).""" |     """Check that we also capture warnings issued during test collection (#3251).""" | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|  | @ -321,7 +323,7 @@ def test_collection_warnings(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("always") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| def test_mark_regex_escape(pytester: Pytester) -> None: | def test_mark_regex_escape(pytester: Pytester) -> None: | ||||||
|     """@pytest.mark.filterwarnings should not try to escape regex characters (#3936)""" |     """@pytest.mark.filterwarnings should not try to escape regex characters (#3936)""" | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|  | @ -337,7 +339,7 @@ def test_mark_regex_escape(pytester: Pytester) -> None: | ||||||
|     assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() |     assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("default") | @pytest.mark.filterwarnings("default::pytest.PytestWarning") | ||||||
| @pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"]) | @pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"]) | ||||||
| def test_hide_pytest_internal_warnings( | def test_hide_pytest_internal_warnings( | ||||||
|     pytester: Pytester, ignore_pytest_warnings |     pytester: Pytester, ignore_pytest_warnings | ||||||
|  | @ -387,7 +389,7 @@ def test_option_precedence_cmdline_over_ini( | ||||||
|     pytester.makeini( |     pytester.makeini( | ||||||
|         """ |         """ | ||||||
|         [pytest] |         [pytest] | ||||||
|         filterwarnings = error |         filterwarnings = error::UserWarning | ||||||
|     """ |     """ | ||||||
|     ) |     ) | ||||||
|     pytester.makepyfile( |     pytester.makepyfile( | ||||||
|  | @ -581,8 +583,7 @@ def test_warnings_checker_twice() -> None: | ||||||
|         warnings.warn("Message B", UserWarning) |         warnings.warn("Message B", UserWarning) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| @pytest.mark.filterwarnings("always") |  | ||||||
| def test_group_warnings_by_message(pytester: Pytester) -> None: | def test_group_warnings_by_message(pytester: Pytester) -> None: | ||||||
|     pytester.copy_example("warnings/test_group_warnings_by_message.py") |     pytester.copy_example("warnings/test_group_warnings_by_message.py") | ||||||
|     result = pytester.runpytest() |     result = pytester.runpytest() | ||||||
|  | @ -613,8 +614,7 @@ def test_group_warnings_by_message(pytester: Pytester) -> None: | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning") | @pytest.mark.filterwarnings("always::UserWarning") | ||||||
| @pytest.mark.filterwarnings("always") |  | ||||||
| def test_group_warnings_by_message_summary(pytester: Pytester) -> None: | def test_group_warnings_by_message_summary(pytester: Pytester) -> None: | ||||||
|     pytester.copy_example("warnings/test_group_warnings_by_message_summary") |     pytester.copy_example("warnings/test_group_warnings_by_message_summary") | ||||||
|     pytester.syspathinsert() |     pytester.syspathinsert() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue