From 34f1a77773f6703875b53722477889bc588b0400 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 21 Jul 2024 14:57:28 -0400 Subject: [PATCH] Log filenames when running pytest-mypy --- conftest.py | 15 +++++++++++++++ mypy.ini | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 532e83112a2..657f4131b1f 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,10 @@ +from __future__ import annotations + +import os import sys import pytest +from pytest_mypy import MypyFileItem, MypyResults pytest_plugins = 'setuptools.tests.fixtures' @@ -21,7 +25,18 @@ def pytest_addoption(parser): ) +def mypy_error_formatter_show_filename( + item: MypyFileItem, results: MypyResults, errors: list[str] +) -> str: + """Include the relative file path before each reported error.""" + return '\n'.join( + f'{item.path.relative_to(os.getcwd())}:{error}' for error in errors + ) + + def pytest_configure(config): + mypy_plugin = config.pluginmanager.getplugin('mypy') + mypy_plugin.file_error_formatter = mypy_error_formatter_show_filename config.addinivalue_line("markers", "integration: integration tests") config.addinivalue_line("markers", "uses_network: tests may try to download files") _IntegrationTestSpeedups.disable_plugins_already_run(config) diff --git a/mypy.ini b/mypy.ini index 4fba13c2869..10314dfd14d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -35,7 +35,8 @@ disable_error_code = import-not-found # - All jaraco modules are still untyped # - _validate_project sometimes complains about trove_classifiers (#4296) # - wheel appears to be untyped -[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*] +# - pytest_mypy isn't marked as py.typed +[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*,pytest_mypy.*] ignore_missing_imports = True # Even when excluding a module, import issues can show up due to following import