Skip to content

Commit

Permalink
Remove support for pytest 6.x (#151)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
delfick committed May 4, 2024
1 parent 3995a96 commit bb643e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
22 changes: 5 additions & 17 deletions pytest_mypy_plugins/collect.py
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions pytest_mypy_plugins/item.py
Expand Up @@ -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

0 comments on commit bb643e6

Please sign in to comment.