@@ -144,9 +144,9 @@ def __invert__(self: _T) -> _T: pass
144
144
"""
145
145
146
146
147
- def run_stubtest (
147
+ def run_stubtest_with_stderr (
148
148
stub : str , runtime : str , options : list [str ], config_file : str | None = None
149
- ) -> str :
149
+ ) -> tuple [ str , str ] :
150
150
with use_tmp_dir (TEST_MODULE_NAME ) as tmp_dir :
151
151
with open ("builtins.pyi" , "w" ) as f :
152
152
f .write (stubtest_builtins_stub )
@@ -163,13 +163,26 @@ def run_stubtest(
163
163
f .write (config_file )
164
164
options = options + ["--mypy-config-file" , f"{ TEST_MODULE_NAME } _config.ini" ]
165
165
output = io .StringIO ()
166
- with contextlib .redirect_stdout (output ):
166
+ outerr = io .StringIO ()
167
+ with contextlib .redirect_stdout (output ), contextlib .redirect_stderr (outerr ):
167
168
test_stubs (parse_options ([TEST_MODULE_NAME ] + options ), use_builtins_fixtures = True )
168
- return remove_color_code (
169
- output .getvalue ()
170
- # remove cwd as it's not available from outside
171
- .replace (os .path .realpath (tmp_dir ) + os .sep , "" ).replace (tmp_dir + os .sep , "" )
172
- )
169
+ filtered_output = remove_color_code (
170
+ output .getvalue ()
171
+ # remove cwd as it's not available from outside
172
+ .replace (os .path .realpath (tmp_dir ) + os .sep , "" ).replace (tmp_dir + os .sep , "" )
173
+ )
174
+ filtered_outerr = remove_color_code (
175
+ outerr .getvalue ()
176
+ # remove cwd as it's not available from outside
177
+ .replace (os .path .realpath (tmp_dir ) + os .sep , "" ).replace (tmp_dir + os .sep , "" )
178
+ )
179
+ return filtered_output , filtered_outerr
180
+
181
+
182
+ def run_stubtest (
183
+ stub : str , runtime : str , options : list [str ], config_file : str | None = None
184
+ ) -> str :
185
+ return run_stubtest_with_stderr (stub , runtime , options , config_file )[0 ]
173
186
174
187
175
188
class Case :
@@ -2590,6 +2603,19 @@ def test_config_file_error_codes(self) -> None:
2590
2603
output = run_stubtest (stub = stub , runtime = runtime , options = [], config_file = config_file )
2591
2604
assert output == "Success: no issues found in 1 module\n "
2592
2605
2606
+ def test_config_file_error_codes_invalid (self ) -> None :
2607
+ runtime = "temp = 5\n "
2608
+ stub = "temp: int\n "
2609
+ config_file = "[mypy]\n disable_error_code = not-a-valid-name\n "
2610
+ output , outerr = run_stubtest_with_stderr (
2611
+ stub = stub , runtime = runtime , options = [], config_file = config_file
2612
+ )
2613
+ assert output == "Success: no issues found in 1 module\n "
2614
+ assert outerr == (
2615
+ "test_module_config.ini: [mypy]: disable_error_code: "
2616
+ "Invalid error code(s): not-a-valid-name\n "
2617
+ )
2618
+
2593
2619
def test_config_file_wrong_incomplete_feature (self ) -> None :
2594
2620
runtime = "x = 1\n "
2595
2621
stub = "x: int\n "
0 commit comments