Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log filenames when running pytest-mypy #4502

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,7 +24,18 @@ def pytest_addoption(parser):
)


def mypy_error_formatter_show_filename(
item: MypyFileItem, results: MypyResults, errors: list[str]
) -> str: # pragma: nocover # This shouldn't run on success
"""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
Loading