Skip to content

Commit 6c16a39

Browse files
committed
Log filenames when running pytest-mypy
1 parent 08bd311 commit 6c16a39

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

conftest.py

Lines changed: 15 additions & 0 deletions
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

610
pytest_plugins = 'setuptools.tests.fixtures'
@@ -21,7 +25,18 @@ def pytest_addoption(parser):
2125
)
2226

2327

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

mypy.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ disable_error_code = import-not-found
3535
# - All jaraco modules are still untyped
3636
# - _validate_project sometimes complains about trove_classifiers (#4296)
3737
# - wheel appears to be untyped
38-
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*]
38+
# - pytest_mypy isn't marked as py.typed
39+
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*,pytest_mypy.*]
3940
ignore_missing_imports = True
4041

4142
# Even when excluding a module, import issues can show up due to following import

0 commit comments

Comments
 (0)