@@ -68,10 +68,13 @@ 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_default_report_style == "mypy" :
75
+ return "\n " .join (lines )
76
+ # "pytest" style
77
+ return "\n " .join (line .partition (":" )[2 ].strip () for line in lines )
75
78
76
79
77
80
file_error_formatter = default_file_error_formatter
@@ -92,6 +95,14 @@ def pytest_addoption(parser: pytest.Parser) -> None:
92
95
type = str ,
93
96
help = "adds custom mypy config file" ,
94
97
)
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
+ )
95
106
group .addoption (
96
107
"--mypy-no-status-check" ,
97
108
action = "store_true" ,
@@ -175,6 +186,7 @@ def pytest_configure(config: pytest.Config) -> None:
175
186
[
176
187
config .option .mypy ,
177
188
config .option .mypy_config_file ,
189
+ config .option .mypy_default_report_style ,
178
190
config .option .mypy_ignore_missing_imports ,
179
191
config .option .mypy_no_status_check ,
180
192
config .option .mypy_xfail ,
@@ -268,13 +280,7 @@ def runtest(self) -> None:
268
280
reason = "mypy errors are expected by --mypy-xfail." ,
269
281
)
270
282
)
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 ))
278
284
279
285
def reportinfo (self ) -> Tuple [Path , None , str ]:
280
286
"""Produce a heading for the test report."""
0 commit comments