File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import os
14import sys
25
36import pytest
7+ from pytest_mypy import MypyFileItem , MypyResults
48
59pytest_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+
2336def 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 )
You can’t perform that action at this time.
0 commit comments