Skip to content

Commit

Permalink
Log filenames when running pytest-mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jul 21, 2024
1 parent 08bd311 commit 34f1a77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 34f1a77

Please sign in to comment.