File tree Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ Ilya Konstantinov
201201Ionuț Turturică
202202Isaac Virshup
203203Israel Fruchter
204+ Israël Hallé
204205Itxaso Aizpurua
205206Iwan Briquemont
206207Jaap Broekhuizen
Original file line number Diff line number Diff line change 1+ Do not fail when a warning category cannot be imported. Log a warning instead.
Original file line number Diff line number Diff line change @@ -1965,6 +1965,8 @@ def parse_warning_filter(
19651965 raise UsageError (error_template .format (error = str (e ))) from None
19661966 try :
19671967 category : type [Warning ] = _resolve_warning_category (category_ )
1968+ except ImportError :
1969+ raise
19681970 except Exception :
19691971 exc_info = ExceptionInfo .from_current ()
19701972 exception_text = exc_info .getrepr (style = "native" )
@@ -2023,7 +2025,15 @@ def apply_warning_filters(
20232025 # Filters should have this precedence: cmdline options, config.
20242026 # Filters should be applied in the inverse order of precedence.
20252027 for arg in config_filters :
2026- warnings .filterwarnings (* parse_warning_filter (arg , escape = False ))
2028+ try :
2029+ warnings .filterwarnings (* parse_warning_filter (arg , escape = False ))
2030+ except ImportError as e :
2031+ warnings .warn (f"Failed to import filter module '{ e .name } ': { arg } " , PytestConfigWarning )
2032+ continue
20272033
20282034 for arg in cmdline_filters :
2029- warnings .filterwarnings (* parse_warning_filter (arg , escape = True ))
2035+ try :
2036+ warnings .filterwarnings (* parse_warning_filter (arg , escape = True ))
2037+ except ImportError as e :
2038+ warnings .warn (f"Failed to import filter module '{ e .name } ': { arg } " , PytestConfigWarning )
2039+ continue
Original file line number Diff line number Diff line change @@ -424,6 +424,32 @@ def test():
424424 result .stdout .fnmatch_lines (["* 1 failed in*" ])
425425
426426
427+ def test_accept_unknown_category (pytester : Pytester ) -> None :
428+ """Category types that can't be imported don't cause failure (#13732)."""
429+ pytester .makeini (
430+ """
431+ [pytest]
432+ filterwarnings =
433+ always:Failed to import filter module.*:pytest.PytestConfigWarning
434+ ignore::foobar.Foobar
435+ """
436+ )
437+ pytester .makepyfile (
438+ """
439+ def test():
440+ pass
441+ """
442+ )
443+ result = pytester .runpytest ("-W" , "ignore::bizbaz.Bizbaz" )
444+ result .stdout .fnmatch_lines (
445+ [
446+ f"*== { WARNINGS_SUMMARY_HEADER } ==*" ,
447+ "*PytestConfigWarning: Failed to import filter module 'bizbaz': ignore::bizbaz.Bizbaz" ,
448+ "* 1 passed, * warning*" ,
449+ ]
450+ )
451+
452+
427453class TestDeprecationWarningsByDefault :
428454 """
429455 Note: all pytest runs are executed in a subprocess so we don't inherit warning filters
You can’t perform that action at this time.
0 commit comments