File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ Ilya Konstantinov
201
201
Ionuț Turturică
202
202
Isaac Virshup
203
203
Israel Fruchter
204
+ Israël Hallé
204
205
Itxaso Aizpurua
205
206
Iwan Briquemont
206
207
Jaap 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(
1965
1965
raise UsageError (error_template .format (error = str (e ))) from None
1966
1966
try :
1967
1967
category : type [Warning ] = _resolve_warning_category (category_ )
1968
+ except ImportError :
1969
+ raise
1968
1970
except Exception :
1969
1971
exc_info = ExceptionInfo .from_current ()
1970
1972
exception_text = exc_info .getrepr (style = "native" )
@@ -2023,7 +2025,19 @@ def apply_warning_filters(
2023
2025
# Filters should have this precedence: cmdline options, config.
2024
2026
# Filters should be applied in the inverse order of precedence.
2025
2027
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 (
2032
+ f"Failed to import filter module '{ e .name } ': { arg } " , PytestConfigWarning
2033
+ )
2034
+ continue
2027
2035
2028
2036
for arg in cmdline_filters :
2029
- warnings .filterwarnings (* parse_warning_filter (arg , escape = True ))
2037
+ try :
2038
+ warnings .filterwarnings (* parse_warning_filter (arg , escape = True ))
2039
+ except ImportError as e :
2040
+ warnings .warn (
2041
+ f"Failed to import filter module '{ e .name } ': { arg } " , PytestConfigWarning
2042
+ )
2043
+ continue
Original file line number Diff line number Diff line change @@ -424,6 +424,32 @@ def test():
424
424
result .stdout .fnmatch_lines (["* 1 failed in*" ])
425
425
426
426
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
+
427
453
class TestDeprecationWarningsByDefault :
428
454
"""
429
455
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