@@ -56,33 +56,30 @@ def test_positive_cases(
5656 else :
5757 expected_filepath = test_file_path .with_suffix (".json" )
5858
59- with warnings .catch_warnings (
60- record = self .VENDOR .unread_data_handled
61- ) as captured_warnings :
62- if not (warn_unread_keys or self .VENDOR .unread_data_handled ):
63- warnings .filterwarnings (
64- "ignore" , ".*went out of scope without reading all keys.*"
65- )
59+ with warnings .catch_warnings (record = True ) as captured_warnings :
6660 allotrope_dict = from_file (
6761 str (test_file_path ), self .VENDOR , encoding = CHARDET_ENCODING
6862 )
6963
7064 # If parser is marked as having unread data handled, error on any unread data warnings.
71- if self .VENDOR .unread_data_handled and captured_warnings :
72- for captured_warning in captured_warnings :
73- warnings .warn_explicit (
74- message = captured_warning .message ,
75- category = captured_warning .category ,
76- filename = captured_warning .filename ,
77- lineno = captured_warning .lineno ,
78- source = captured_warning .source ,
79- )
80- warning = captured_warning .message
81- if isinstance (
82- warning , UserWarning
83- ) and "went out of scope without reading all keys" in str (warning ):
65+ for captured_warning in captured_warnings :
66+ if isinstance (
67+ captured_warning .message , UserWarning
68+ ) and "went out of scope without reading all keys" in str (
69+ captured_warning .message
70+ ):
71+ if self .VENDOR .unread_data_handled :
8472 msg = "Parser is marked as UNREAD_DATA_HANDLED, but had unread data warnings!"
8573 raise AssertionError (msg )
74+ if not warn_unread_keys :
75+ continue
76+ warnings .warn_explicit (
77+ message = captured_warning .message ,
78+ category = captured_warning .category ,
79+ filename = captured_warning .filename ,
80+ lineno = captured_warning .lineno ,
81+ source = captured_warning .source ,
82+ )
8683
8784 # If expected output does not exist, assume this is a new file and write it.
8885 overwrite = overwrite or not expected_filepath .exists ()
0 commit comments