From 6afe15e4a254a203836b5cdfa67ad9cc35678ec3 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Mon, 10 Feb 2020 19:24:53 -0800 Subject: [PATCH 1/7] Require Pytest 5+ --- pyproject.toml | 2 +- tox.ini | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index eb58fef..64aea48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ "attrs>=19.0", "filelock>=3.0", "mypy>=1.0", - "pytest>=4.6", + "pytest>=5.0", ] [project.entry-points.pytest11] diff --git a/tox.ini b/tox.ini index f8ebf12..ecb81dd 100644 --- a/tox.ini +++ b/tox.ini @@ -3,9 +3,9 @@ minversion = 4.4 isolated_build = true envlist = - py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py37-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} + py38-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py39-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} @@ -14,9 +14,9 @@ envlist = [gh-actions] python = - 3.7: py37-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - 3.8: py38-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static - 3.9: py39-pytest{4.6, 5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.7: py37-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} + 3.8: py38-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static + 3.9: py39-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.10: py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.11: py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.12: py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} @@ -24,7 +24,6 @@ python = [testenv] constrain_package_deps = true deps = - pytest4.6: pytest ~= 4.6.0 pytest5.0: pytest ~= 5.0.0 pytest5.x: pytest ~= 5.0 pytest6.0: pytest ~= 6.0.0 From f1aed2a0fa516eb06e518bc1d996852aa07b51da Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sat, 22 Jun 2019 23:56:17 -0700 Subject: [PATCH 2/7] Use pytest.ExitCode in tests --- tests/test_pytest_mypy.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/test_pytest_mypy.py b/tests/test_pytest_mypy.py index e5b9670..c3f9383 100644 --- a/tests/test_pytest_mypy.py +++ b/tests/test_pytest_mypy.py @@ -53,12 +53,13 @@ def pyfunc(x: int) -> int: ) result = testdir.runpytest_subprocess(*xdist_args) result.assert_outcomes() + assert result.ret == pytest.ExitCode.NO_TESTS_COLLECTED result = testdir.runpytest_subprocess("--mypy", *xdist_args) mypy_file_checks = pyfile_count mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_mypy_pyi(testdir, xdist_args): @@ -89,7 +90,7 @@ def pyfunc(x: int) -> int: ... mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_mypy_error(testdir, xdist_args): @@ -103,14 +104,15 @@ def pyfunc(x: int) -> str: result = testdir.runpytest_subprocess(*xdist_args) result.assert_outcomes() assert "_mypy_results_path" not in result.stderr.str() + assert result.ret == pytest.ExitCode.NO_TESTS_COLLECTED result = testdir.runpytest_subprocess("--mypy", *xdist_args) mypy_file_checks = 1 mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(failed=mypy_checks) result.stdout.fnmatch_lines(["2: error: Incompatible return value*"]) - assert result.ret != 0 assert "_mypy_results_path" not in result.stderr.str() + assert result.ret == pytest.ExitCode.TESTS_FAILED def test_mypy_annotation_unchecked(testdir, xdist_args, tmp_path, monkeypatch): @@ -131,7 +133,7 @@ def pyfunc(x): outcomes = {"passed": mypy_checks} result.assert_outcomes(**outcomes) result.stdout.fnmatch_lines(["*MypyWarning*"]) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_mypy_ignore_missings_imports(testdir, xdist_args): @@ -162,10 +164,10 @@ def test_mypy_ignore_missings_imports(testdir, xdist_args): ), ], ) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED result = testdir.runpytest_subprocess("--mypy-ignore-missing-imports", *xdist_args) result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_mypy_config_file(testdir, xdist_args): @@ -181,7 +183,7 @@ def pyfunc(x): mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK mypy_config_file = testdir.makeini( """ [mypy] @@ -210,10 +212,10 @@ def test_fails(): mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(failed=test_count, passed=mypy_checks) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED result = testdir.runpytest_subprocess("--mypy", "-m", "mypy", *xdist_args) result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_non_mypy_error(testdir, xdist_args): @@ -235,6 +237,7 @@ def runtest(self): ) result = testdir.runpytest_subprocess(*xdist_args) result.assert_outcomes() + assert result.ret == pytest.ExitCode.NO_TESTS_COLLECTED result = testdir.runpytest_subprocess("--mypy", *xdist_args) mypy_file_checks = 1 # conftest.py mypy_status_check = 1 @@ -243,7 +246,7 @@ def runtest(self): passed=mypy_status_check, # conftest.py has no type errors. ) result.stdout.fnmatch_lines(["*" + message]) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED def test_mypy_stderr(testdir, xdist_args): @@ -294,7 +297,7 @@ def pytest_configure(config): """, ) result = testdir.runpytest_subprocess("--mypy", *xdist_args) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_api_nodeid_name(testdir, xdist_args): @@ -311,7 +314,7 @@ def pytest_configure(config): ) result = testdir.runpytest_subprocess("--mypy", "--verbose", *xdist_args) result.stdout.fnmatch_lines(["*conftest.py::" + nodeid_name + "*"]) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK @pytest.mark.xfail( @@ -352,7 +355,7 @@ def pyfunc(x: int) -> str: mypy_file_checks = 1 mypy_status_check = 1 result.assert_outcomes(passed=mypy_file_checks, failed=mypy_status_check) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED def test_api_error_formatter(testdir, xdist_args): @@ -381,7 +384,7 @@ def pytest_configure(config): ) result = testdir.runpytest_subprocess("--mypy", *xdist_args) result.stdout.fnmatch_lines(["*/bad.py:2: error: Incompatible return value*"]) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED def test_pyproject_toml(testdir, xdist_args): @@ -401,7 +404,7 @@ def pyfunc(x): ) result = testdir.runpytest_subprocess("--mypy", *xdist_args) result.stdout.fnmatch_lines(["1: error: Function is missing a type annotation*"]) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED def test_setup_cfg(testdir, xdist_args): @@ -421,7 +424,7 @@ def pyfunc(x): ) result = testdir.runpytest_subprocess("--mypy", *xdist_args) result.stdout.fnmatch_lines(["1: error: Function is missing a type annotation*"]) - assert result.ret != 0 + assert result.ret == pytest.ExitCode.TESTS_FAILED @pytest.mark.parametrize("module_name", ["__init__", "test_demo"]) @@ -558,7 +561,7 @@ def test_mypy_item_collect(request): mypy_file_checks = 1 mypy_status_check = 1 result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK def test_mypy_results_from_mypy_with_opts(): @@ -610,5 +613,5 @@ def pytest_terminal_summary(config): mypy_status_check = 1 mypy_checks = mypy_file_checks + mypy_status_check result.assert_outcomes(passed=mypy_checks) - assert result.ret == 0 + assert result.ret == pytest.ExitCode.OK assert f"= {pytest_mypy.terminal_summary_title} =" not in str(result.stdout) From af3b814b8496a05a7e835ddf8129dc446c2637ba Mon Sep 17 00:00:00 2001 From: David Tucker Date: Fri, 8 Mar 2024 00:08:40 -0800 Subject: [PATCH 3/7] Remove obsolete "no cover" --- src/pytest_mypy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 4a272ff..b30b3a1 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -258,9 +258,7 @@ def from_mypy( ) -> "MypyResults": """Generate results from mypy.""" - # This is covered by test_mypy_results_from_mypy_with_opts; - # however, coverage is not recognized on py38-pytest4.6: - if opts is None: # pragma: no cover + if opts is None: opts = mypy_argv[:] abspath_errors = { str(path.absolute()): [] for path in paths From 00ad34171a6d3c55c5ce7096ee71b893e2d0dec3 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Wed, 5 Aug 2020 21:36:07 -0700 Subject: [PATCH 4/7] Require Pytest 6+ --- pyproject.toml | 2 +- src/pytest_mypy.py | 23 ++--------------------- tests/test_pytest_mypy.py | 24 ------------------------ tox.ini | 14 ++++++-------- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 64aea48..93908e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ "attrs>=19.0", "filelock>=3.0", "mypy>=1.0", - "pytest>=5.0", + "pytest>=6.0", ] [project.entry-points.pytest11] diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index b30b3a1..7618cfa 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -10,7 +10,7 @@ import attr from filelock import FileLock # type: ignore import mypy.api -import pytest # type: ignore +import pytest PYTEST_MAJOR_VERSION = int(pytest.__version__.partition(".")[0]) @@ -141,12 +141,6 @@ def pytest_collect_file(path, parent): # type: ignore class MypyFile(pytest.File): """A File that Mypy will run on.""" - @classmethod - def from_parent(cls, *args, **kwargs): - """Override from_parent for compatibility.""" - # pytest.File.from_parent did not exist before pytest 5.4. - return getattr(super(), "from_parent", cls)(*args, **kwargs) - def collect(self): """Create a MypyFileItem for the File.""" yield MypyFileItem.from_parent(parent=self, name=nodeid_name) @@ -169,19 +163,6 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.add_marker(self.MARKER) - def collect(self): - """ - Partially work around https://github.com/pytest-dev/pytest/issues/8016 - for pytest < 6.0 with --looponfail. - """ - yield self - - @classmethod - def from_parent(cls, *args, **kwargs): - """Override from_parent for compatibility.""" - # pytest.Item.from_parent did not exist before pytest 5.4. - return getattr(super(), "from_parent", cls)(*args, **kwargs) - def repr_failure(self, excinfo): """ Unwrap mypy errors so we get a clean error message without the @@ -213,7 +194,7 @@ def reportinfo(self): return ( self.fspath, None, - self.config.invocation_dir.bestrelpath(self.fspath), + str(Path(str(self.fspath)).relative_to(self.config.invocation_params.dir)), ) diff --git a/tests/test_pytest_mypy.py b/tests/test_pytest_mypy.py index c3f9383..1192600 100644 --- a/tests/test_pytest_mypy.py +++ b/tests/test_pytest_mypy.py @@ -540,30 +540,6 @@ def _break(): child.kill(signal.SIGTERM) -def test_mypy_item_collect(testdir, xdist_args): - """Ensure coverage for a 3.10<=pytest<6.0 workaround.""" - testdir.makepyfile( - """ - def test_mypy_item_collect(request): - plugin = request.config.pluginmanager.getplugin("mypy") - mypy_items = [ - item - for item in request.session.items - if isinstance(item, plugin.MypyItem) - ] - assert mypy_items - for mypy_item in mypy_items: - assert all(item is mypy_item for item in mypy_item.collect()) - """, - ) - result = testdir.runpytest_subprocess("--mypy", *xdist_args) - test_count = 1 - mypy_file_checks = 1 - mypy_status_check = 1 - result.assert_outcomes(passed=test_count + mypy_file_checks + mypy_status_check) - assert result.ret == pytest.ExitCode.OK - - def test_mypy_results_from_mypy_with_opts(): """MypyResults.from_mypy respects passed options.""" mypy_results = pytest_mypy.MypyResults.from_mypy([], opts=["--version"]) diff --git a/tox.ini b/tox.ini index ecb81dd..7782dcd 100644 --- a/tox.ini +++ b/tox.ini @@ -3,9 +3,9 @@ minversion = 4.4 isolated_build = true envlist = - py37-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - py38-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py39-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py37-pytest{6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} + py38-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py39-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} @@ -14,9 +14,9 @@ envlist = [gh-actions] python = - 3.7: py37-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - 3.8: py38-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static - 3.9: py39-pytest{5.0, 5.x, 6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.7: py37-pytest{6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} + 3.8: py38-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static + 3.9: py39-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.10: py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.11: py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} 3.12: py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} @@ -24,8 +24,6 @@ python = [testenv] constrain_package_deps = true deps = - pytest5.0: pytest ~= 5.0.0 - pytest5.x: pytest ~= 5.0 pytest6.0: pytest ~= 6.0.0 pytest6.2: pytest ~= 6.2.0 pytest6.x: pytest ~= 6.0 From 9e3c6b4769e8ad470a2227699960fae562636053 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sun, 6 Feb 2022 23:13:54 -0800 Subject: [PATCH 5/7] Require Pytest 7+ --- pyproject.toml | 2 +- src/pytest_mypy.py | 13 ------------- tox.ini | 27 ++++++++++++--------------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 93908e3..7483076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ "attrs>=19.0", "filelock>=3.0", "mypy>=1.0", - "pytest>=6.0", + "pytest>=7.0", ] [project.entry-points.pytest11] diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 7618cfa..1dbe671 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -13,7 +13,6 @@ import pytest -PYTEST_MAJOR_VERSION = int(pytest.__version__.partition(".")[0]) mypy_argv = [] nodeid_name = "mypy" terminal_summary_title = "mypy" @@ -126,18 +125,6 @@ def pytest_collect_file(file_path, parent): return None -if PYTEST_MAJOR_VERSION < 7: # pragma: no cover - _pytest_collect_file = pytest_collect_file - - def pytest_collect_file(path, parent): # type: ignore - try: - # https://docs.pytest.org/en/7.0.x/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path - return _pytest_collect_file(Path(str(path)), parent) - except TypeError: - # https://docs.pytest.org/en/7.0.x/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path - return MypyFile.from_parent(parent=parent, fspath=path) - - class MypyFile(pytest.File): """A File that Mypy will run on.""" diff --git a/tox.ini b/tox.ini index 7782dcd..0a6adcc 100644 --- a/tox.ini +++ b/tox.ini @@ -3,30 +3,27 @@ minversion = 4.4 isolated_build = true envlist = - py37-pytest{6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - py38-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py39-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py37-pytest{7.0, 7.x}-mypy{1.0, 1.x} + py38-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py39-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py310-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py311-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + py312-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} publish static [gh-actions] python = - 3.7: py37-pytest{6.0, 6.x, 7.0, 7.x}-mypy{1.0, 1.x} - 3.8: py38-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static - 3.9: py39-pytest{6.0, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - 3.10: py310-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - 3.11: py311-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} - 3.12: py312-pytest{6.2, 6.x, 7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.7: py37-pytest{7.0, 7.x}-mypy{1.0, 1.x} + 3.8: py38-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x}, publish, static + 3.9: py39-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.10: py310-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.11: py311-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} + 3.12: py312-pytest{7.0, 7.x, 8.0, 8.x}-mypy{1.0, 1.x} [testenv] constrain_package_deps = true deps = - pytest6.0: pytest ~= 6.0.0 - pytest6.2: pytest ~= 6.2.0 - pytest6.x: pytest ~= 6.0 pytest7.0: pytest ~= 7.0.0 pytest7.x: pytest ~= 7.0 pytest8.0: pytest ~= 8.0.0 From 7acfaeb4e838e2a984d1b8f9d2bc5872404c4eae Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sun, 11 Aug 2024 15:00:34 -0700 Subject: [PATCH 6/7] Replace item.fspath with item.path --- src/pytest_mypy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 1dbe671..5487ab9 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -166,7 +166,7 @@ class MypyFileItem(MypyItem): def runtest(self): """Raise an exception if mypy found errors for this item.""" results = MypyResults.from_session(self.session) - abspath = os.path.abspath(str(self.fspath)) + abspath = str(self.path.absolute()) errors = results.abspath_errors.get(abspath) if errors: if not all( @@ -179,9 +179,9 @@ def runtest(self): def reportinfo(self): """Produce a heading for the test report.""" return ( - self.fspath, + self.path, None, - str(Path(str(self.fspath)).relative_to(self.config.invocation_params.dir)), + str(self.path.relative_to(self.config.invocation_params.dir)), ) @@ -271,7 +271,7 @@ def from_session(cls, session) -> "MypyResults": except FileNotFoundError: results = cls.from_mypy( [ - Path(item.fspath) + item.path for item in session.items if isinstance(item, MypyFileItem) ], From 0ac85af3a3c6ac7facaa289349f856757147cdf3 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sun, 11 Aug 2024 15:07:18 -0700 Subject: [PATCH 7/7] Remove os dep --- src/pytest_mypy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 5487ab9..76eb0af 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -1,7 +1,6 @@ """Mypy static type checker plugin for Pytest""" import json -import os from pathlib import Path from tempfile import NamedTemporaryFile from typing import Dict, List, Optional, TextIO @@ -232,8 +231,9 @@ def from_mypy( str(path.absolute()): [] for path in paths } # type: MypyResults._abspath_errors_type + cwd = Path.cwd() stdout, stderr, status = mypy.api.run( - opts + [os.path.relpath(key) for key in abspath_errors.keys()] + opts + [str(Path(key).relative_to(cwd)) for key in abspath_errors.keys()] ) unmatched_lines = [] @@ -241,7 +241,7 @@ def from_mypy( if not line: continue path, _, error = line.partition(":") - abspath = os.path.abspath(path) + abspath = str(Path(path).absolute()) try: abspath_errors[abspath].append(error) except KeyError: @@ -310,4 +310,4 @@ def pytest_terminal_summary(terminalreporter, config): terminalreporter.write_line(results.unmatched_stdout, **color) if results.stderr: terminalreporter.write_line(results.stderr, yellow=True) - os.remove(config._mypy_results_path) + Path(config._mypy_results_path).unlink()