@@ -68,10 +68,12 @@ def default_test_name_formatter(*, item: MypyFileItem) -> str:
68
68
def default_file_error_formatter (
69
69
item : MypyItem ,
70
70
results : MypyResults ,
71
- errors : List [str ],
71
+ lines : List [str ],
72
72
) -> str :
73
73
"""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 )
75
77
76
78
77
79
file_error_formatter = default_file_error_formatter
@@ -92,6 +94,16 @@ def pytest_addoption(parser: pytest.Parser) -> None:
92
94
type = str ,
93
95
help = "adds custom mypy config file" ,
94
96
)
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
+ )
95
107
group .addoption (
96
108
"--mypy-no-status-check" ,
97
109
action = "store_true" ,
@@ -175,6 +187,7 @@ def pytest_configure(config: pytest.Config) -> None:
175
187
[
176
188
config .option .mypy ,
177
189
config .option .mypy_config_file ,
190
+ config .option .mypy_report_style ,
178
191
config .option .mypy_ignore_missing_imports ,
179
192
config .option .mypy_no_status_check ,
180
193
config .option .mypy_xfail ,
@@ -268,13 +281,7 @@ def runtest(self) -> None:
268
281
reason = "mypy errors are expected by --mypy-xfail." ,
269
282
)
270
283
)
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 ))
278
285
279
286
def reportinfo (self ) -> Tuple [Path , None , str ]:
280
287
"""Produce a heading for the test report."""
0 commit comments