@@ -68,10 +68,12 @@ 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_report_style == "mypy" :
75+ return "\n " .join (lines )
76+ return "\n " .join (line .partition (":" )[2 ].strip () for line in lines )
7577
7678
7779file_error_formatter = default_file_error_formatter
@@ -92,6 +94,16 @@ def pytest_addoption(parser: pytest.Parser) -> None:
9294 type = str ,
9395 help = "adds custom mypy config file" ,
9496 )
97+ styles = {
98+ "mypy" : "modify the original mypy output as little as possible" ,
99+ "no-path" : "(default) strip the path prefix from mypy errors" ,
100+ }
101+ group .addoption (
102+ "--mypy-report-style" ,
103+ choices = list (styles ),
104+ help = "change the way mypy output is reported:\n "
105+ + "\n " .join (f"- { name } : { desc } " for name , desc in styles .items ()),
106+ )
95107 group .addoption (
96108 "--mypy-no-status-check" ,
97109 action = "store_true" ,
@@ -175,6 +187,7 @@ def pytest_configure(config: pytest.Config) -> None:
175187 [
176188 config .option .mypy ,
177189 config .option .mypy_config_file ,
190+ config .option .mypy_report_style ,
178191 config .option .mypy_ignore_missing_imports ,
179192 config .option .mypy_no_status_check ,
180193 config .option .mypy_xfail ,
@@ -268,13 +281,7 @@ def runtest(self) -> None:
268281 reason = "mypy errors are expected by --mypy-xfail." ,
269282 )
270283 )
271- raise MypyError (
272- file_error_formatter (
273- self ,
274- results ,
275- errors = [line .partition (":" )[2 ].strip () for line in lines ],
276- )
277- )
284+ raise MypyError (file_error_formatter (self , results , lines ))
278285
279286 def reportinfo (self ) -> Tuple [Path , None , str ]:
280287 """Produce a heading for the test report."""
0 commit comments