@@ -399,32 +399,27 @@ def pyfunc(x: int) -> str:
399
399
assert result .ret == pytest .ExitCode .TESTS_FAILED
400
400
401
401
402
- def test_api_error_formatter (testdir , xdist_args ):
403
- """Ensure that the plugin can be configured in a conftest.py."""
402
+ def test_api_file_error_formatter (testdir , xdist_args ):
403
+ """Ensure that the file_error_formatter can be replaced in a conftest.py."""
404
404
testdir .makepyfile (
405
405
bad = """
406
406
def pyfunc(x: int) -> str:
407
407
return x * 2
408
408
""" ,
409
409
)
410
+ file_error = "UnmistakableFileError"
410
411
testdir .makepyfile (
411
- conftest = """
412
- def custom_file_error_formatter(item, results, errors):
413
- return '\\ n'.join(
414
- '{path}:{error}'.format(
415
- path=item.fspath,
416
- error=error,
417
- )
418
- for error in errors
419
- )
412
+ conftest = f"""
413
+ def custom_file_error_formatter(item, results, lines):
414
+ return '{ file_error } '
420
415
421
416
def pytest_configure(config):
422
417
plugin = config.pluginmanager.getplugin('mypy')
423
418
plugin.file_error_formatter = custom_file_error_formatter
424
419
""" ,
425
420
)
426
421
result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
427
- result .stdout .fnmatch_lines (["*/bad.py:2: error: Incompatible return value *" ])
422
+ result .stdout .fnmatch_lines ([f"* { file_error } *" ])
428
423
assert result .ret == pytest .ExitCode .TESTS_FAILED
429
424
430
425
@@ -671,3 +666,29 @@ def pytest_configure(config):
671
666
def test_error_severity ():
672
667
"""Verify that non-error lines produce no severity."""
673
668
assert pytest_mypy ._error_severity ("arbitrary line with no error" ) is None
669
+
670
+
671
+ def test_mypy_report_style (testdir , xdist_args ):
672
+ """Verify that --mypy-report-style functions correctly."""
673
+ module_name = "unmistakable_module_name"
674
+ testdir .makepyfile (
675
+ ** {
676
+ module_name : """
677
+ def pyfunc(x: int) -> str:
678
+ return x * 2
679
+ """
680
+ },
681
+ )
682
+ result = testdir .runpytest_subprocess ("--mypy-report-style" , "no-path" , * xdist_args )
683
+ mypy_file_checks = 1
684
+ mypy_status_check = 1
685
+ mypy_checks = mypy_file_checks + mypy_status_check
686
+ result .assert_outcomes (failed = mypy_checks )
687
+ result .stdout .fnmatch_lines (["2: error: Incompatible return value*" ])
688
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
689
+ result = testdir .runpytest_subprocess ("--mypy-report-style" , "mypy" , * xdist_args )
690
+ result .assert_outcomes (failed = mypy_checks )
691
+ result .stdout .fnmatch_lines (
692
+ [f"{ module_name } .py:2: error: Incompatible return value*" ]
693
+ )
694
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
0 commit comments