From bb643e60e6132e80a37e46789af386f2a326ac83 Mon Sep 17 00:00:00 2001 From: Stephen Moore Date: Sat, 4 May 2024 17:23:02 +1000 Subject: [PATCH] Remove support for pytest 6.x (#151) Pytest 7 was released over two years ago, and this repository no longer tests against pytest 6. It should be safe to assume that projects aren't relying on pytest 6 anymore. fixes: #150 --- pytest_mypy_plugins/collect.py | 22 +++++----------------- pytest_mypy_plugins/item.py | 7 ++----- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/pytest_mypy_plugins/collect.py b/pytest_mypy_plugins/collect.py index 8bb3622..34b9fe5 100644 --- a/pytest_mypy_plugins/collect.py +++ b/pytest_mypy_plugins/collect.py @@ -23,7 +23,6 @@ import yaml from _pytest.config.argparsing import Parser from _pytest.nodes import Node -from packaging.version import Version from pytest_mypy_plugins import utils @@ -108,9 +107,7 @@ class YamlTestFile(pytest.File): def collect(self) -> Iterator["YamlTestItem"]: from pytest_mypy_plugins.item import YamlTestItem - # To support both Pytest 6.x and 7.x - path = getattr(self, "path", None) or getattr(self, "fspath") - parsed_file = yaml.load(stream=path.read_text("utf8"), Loader=SafeLineLoader) + parsed_file = yaml.load(stream=self.path.read_text("utf8"), Loader=SafeLineLoader) if parsed_file is None: return @@ -174,19 +171,10 @@ def _eval_skip(self, skip_if: str) -> bool: return eval(skip_if, {"sys": sys, "os": os, "pytest": pytest, "platform": platform}) -if Version(pytest.__version__) >= Version("7.0.0rc1"): - - def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlTestFile]: - if file_path.suffix in {".yaml", ".yml"} and file_path.name.startswith(("test-", "test_")): - return YamlTestFile.from_parent(parent, path=file_path, fspath=None) - return None - -else: - - def pytest_collect_file(path: py.path.local, parent: Node) -> Optional[YamlTestFile]: # type: ignore[misc] - if path.ext in {".yaml", ".yml"} and path.basename.startswith(("test-", "test_")): - return YamlTestFile.from_parent(parent, fspath=path) - return None +def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlTestFile]: + if file_path.suffix in {".yaml", ".yml"} and file_path.name.startswith(("test-", "test_")): + return YamlTestFile.from_parent(parent, path=file_path, fspath=None) + return None def pytest_addoption(parser: Parser) -> None: diff --git a/pytest_mypy_plugins/item.py b/pytest_mypy_plugins/item.py index 9d9643d..173809e 100644 --- a/pytest_mypy_plugins/item.py +++ b/pytest_mypy_plugins/item.py @@ -466,8 +466,5 @@ def repr_failure( else: return super().repr_failure(excinfo, style="native") - def reportinfo(self) -> Tuple[Union[py.path.local, Path, str], Optional[int], str]: - # To support both Pytest 6.x and 7.x - path = getattr(self, "path", None) or getattr(self, "fspath") - assert path - return path, None, self.name + def reportinfo(self) -> Tuple[Union[Path, str], Optional[int], str]: + return self.path, None, self.name