Skip to content

Commit dbae4e9

Browse files
committed
Log filenames when running pytest-mypy
1 parent e55c19e commit dbae4e9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

conftest.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from __future__ import annotations
2+
3+
import os
14
import sys
25

36
import pytest
7+
from pytest_mypy import MypyFileItem, MypyResults
48

59
pytest_plugins = 'setuptools.tests.fixtures'
610

@@ -20,7 +24,18 @@ def pytest_addoption(parser):
2024
)
2125

2226

27+
def mypy_error_formatter_show_filename(
28+
item: MypyFileItem, results: MypyResults, errors: list[str]
29+
) -> str: # pragma: nocover # This shouldn't run on success
30+
"""Include the relative file path before each reported error."""
31+
return '\n'.join(
32+
f'{item.path.relative_to(os.getcwd())}:{error}' for error in errors
33+
)
34+
35+
2336
def pytest_configure(config):
37+
mypy_plugin = config.pluginmanager.getplugin('mypy')
38+
mypy_plugin.file_error_formatter = mypy_error_formatter_show_filename
2439
config.addinivalue_line("markers", "integration: integration tests")
2540
config.addinivalue_line("markers", "uses_network: tests may try to download files")
2641
_IntegrationTestSpeedups.disable_plugins_already_run(config)

0 commit comments

Comments
 (0)