@@ -68,10 +68,13 @@ def default_test_name_formatter(*, item: MypyFileItem) -> str:
6868def default_file_error_formatter (
6969 item : MypyItem ,
7070 results : MypyResults ,
71- errors : List [str ],
71+ lines : List [str ],
7272) -> str :
7373 """Create a string to be displayed when mypy finds errors in a file."""
74- return "\n " .join (errors )
74+ if item .config .option .mypy_default_report_style == "mypy" :
75+ return "\n " .join (lines )
76+ # "pytest" style
77+ return "\n " .join (line .partition (":" )[2 ].strip () for line in lines )
7578
7679
7780file_error_formatter = default_file_error_formatter
@@ -92,6 +95,14 @@ def pytest_addoption(parser: pytest.Parser) -> None:
9295 type = str ,
9396 help = "adds custom mypy config file" ,
9497 )
98+ group .addoption (
99+ "--mypy-default-report-style" ,
100+ choices = [
101+ "mypy" ,
102+ "pytest" ,
103+ ],
104+ help = "change the way mypy output is reported" ,
105+ )
95106 group .addoption (
96107 "--mypy-no-status-check" ,
97108 action = "store_true" ,
@@ -175,6 +186,7 @@ def pytest_configure(config: pytest.Config) -> None:
175186 [
176187 config .option .mypy ,
177188 config .option .mypy_config_file ,
189+ config .option .mypy_default_report_style ,
178190 config .option .mypy_ignore_missing_imports ,
179191 config .option .mypy_no_status_check ,
180192 config .option .mypy_xfail ,
@@ -268,13 +280,7 @@ def runtest(self) -> None:
268280 reason = "mypy errors are expected by --mypy-xfail." ,
269281 )
270282 )
271- raise MypyError (
272- file_error_formatter (
273- self ,
274- results ,
275- errors = [line .partition (":" )[2 ].strip () for line in lines ],
276- )
277- )
283+ raise MypyError (file_error_formatter (self , results , lines ))
278284
279285 def reportinfo (self ) -> Tuple [Path , None , str ]:
280286 """Produce a heading for the test report."""
0 commit comments