From dbae4e92c909df18610dc2f071afea6a47888a14 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 27 Aug 2024 11:14:40 -0400 Subject: [PATCH 1/3] Log filenames when running pytest-mypy --- conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/conftest.py b/conftest.py index 01ed2fa2e6..eb052d05ca 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' @@ -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) From 503b6e0c292ce330d2ed6ded7b9fb60270cfa128 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 15 May 2025 11:14:12 -0400 Subject: [PATCH 2/3] Simple config using pytest.ini --- conftest.py | 15 +-------------- pyproject.toml | 2 +- pytest.ini | 1 + 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/conftest.py b/conftest.py index cb65dbc30e..c3b66071fa 100644 --- a/conftest.py +++ b/conftest.py @@ -1,11 +1,9 @@ from __future__ import annotations -import os import platform import sys import pytest -from pytest_mypy import MypyFileItem, MypyResults pytest_plugins = 'setuptools.tests.fixtures' @@ -25,18 +23,7 @@ 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 +def pytest_configure(config) -> None: 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/pyproject.toml b/pyproject.toml index 9715dcf6b5..7f4bc26fcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -131,7 +131,7 @@ enabler = [ type = [ # upstream - "pytest-mypy", + "pytest-mypy>=1.0.1", # local diff --git a/pytest.ini b/pytest.ini index b6efa6f918..4d1de60e47 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,6 +3,7 @@ norecursedirs=dist build .tox .eggs addopts= --doctest-modules --import-mode importlib + --mypy-report-style mypy --doctest-glob=pkg_resources/api_tests.txt consider_namespace_packages=true filterwarnings= From e6b35c96bc772f978d8f0ffaad35f139253c83a0 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 15 May 2025 11:18:05 -0400 Subject: [PATCH 3/3] Discard changes to conftest.py --- conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index c3b66071fa..0807a8d3d0 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import platform import sys @@ -23,7 +21,7 @@ def pytest_addoption(parser): ) -def pytest_configure(config) -> None: +def pytest_configure(config): 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)