File tree 2 files changed +33
-6
lines changed
2 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ def serialized(self) -> str:
57
57
terminal_summary_title = "mypy"
58
58
59
59
60
+ def default_test_name_formatter (* , item : MypyFileItem ) -> str :
61
+ path = item .path .relative_to (item .config .invocation_params .dir )
62
+ return f"[{ terminal_summary_title } ] { path } "
63
+
64
+
65
+ test_name_formatter = default_test_name_formatter
66
+
67
+
60
68
def default_file_error_formatter (
61
69
item : MypyItem ,
62
70
results : MypyResults ,
@@ -268,13 +276,9 @@ def runtest(self) -> None:
268
276
)
269
277
)
270
278
271
- def reportinfo (self ) -> Tuple [str , None , str ]:
279
+ def reportinfo (self ) -> Tuple [Path , None , str ]:
272
280
"""Produce a heading for the test report."""
273
- return (
274
- str (self .path ),
275
- None ,
276
- str (self .path .relative_to (self .config .invocation_params .dir )),
277
- )
281
+ return (self .path , None , test_name_formatter (item = self ))
278
282
279
283
280
284
class MypyStatusItem (MypyItem ):
Original file line number Diff line number Diff line change @@ -342,6 +342,29 @@ def pytest_configure(config):
342
342
assert result .ret == pytest .ExitCode .OK
343
343
344
344
345
+ def test_api_test_name_formatter (testdir , xdist_args ):
346
+ """Ensure that the test_name_formatter can be replaced in a conftest.py."""
347
+ test_name = "UnmistakableTestName"
348
+ testdir .makepyfile (
349
+ conftest = f"""
350
+ cause_a_mypy_error: str = 5
351
+
352
+ def custom_test_name_formatter(item):
353
+ return "{ test_name } "
354
+
355
+ def pytest_configure(config):
356
+ plugin = config.pluginmanager.getplugin('mypy')
357
+ plugin.test_name_formatter = custom_test_name_formatter
358
+ """ ,
359
+ )
360
+ result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
361
+ result .stdout .fnmatch_lines ([f"*{ test_name } *" ])
362
+ mypy_file_check = 1
363
+ mypy_status_check = 1
364
+ result .assert_outcomes (failed = mypy_file_check + mypy_status_check )
365
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
366
+
367
+
345
368
@pytest .mark .xfail (
346
369
Version ("0.971" ) <= MYPY_VERSION ,
347
370
raises = AssertionError ,
You can’t perform that action at this time.
0 commit comments