Skip to content

Commit e236fdb

Browse files
committed
Improve test_api_error_formatter
1 parent fadc662 commit e236fdb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

tests/test_pytest_mypy.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,32 +399,27 @@ def pyfunc(x: int) -> str:
399399
assert result.ret == pytest.ExitCode.TESTS_FAILED
400400

401401

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."""
404404
testdir.makepyfile(
405405
bad="""
406406
def pyfunc(x: int) -> str:
407407
return x * 2
408408
""",
409409
)
410+
file_error = "UnmistakableFileError"
410411
testdir.makepyfile(
411-
conftest="""
412+
conftest=f"""
412413
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-
)
414+
return '{file_error}'
420415
421416
def pytest_configure(config):
422417
plugin = config.pluginmanager.getplugin('mypy')
423418
plugin.file_error_formatter = custom_file_error_formatter
424419
""",
425420
)
426421
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}*"])
428423
assert result.ret == pytest.ExitCode.TESTS_FAILED
429424

430425

0 commit comments

Comments
 (0)