|
23 | 23 | import yaml |
24 | 24 | from _pytest.config.argparsing import Parser |
25 | 25 | from _pytest.nodes import Node |
26 | | -from packaging.version import Version |
27 | 26 |
|
28 | 27 | from pytest_mypy_plugins import utils |
29 | 28 |
|
@@ -108,9 +107,7 @@ class YamlTestFile(pytest.File): |
108 | 107 | def collect(self) -> Iterator["YamlTestItem"]: |
109 | 108 | from pytest_mypy_plugins.item import YamlTestItem |
110 | 109 |
|
111 | | - # To support both Pytest 6.x and 7.x |
112 | | - path = getattr(self, "path", None) or getattr(self, "fspath") |
113 | | - parsed_file = yaml.load(stream=path.read_text("utf8"), Loader=SafeLineLoader) |
| 110 | + parsed_file = yaml.load(stream=self.path.read_text("utf8"), Loader=SafeLineLoader) |
114 | 111 | if parsed_file is None: |
115 | 112 | return |
116 | 113 |
|
@@ -174,19 +171,10 @@ def _eval_skip(self, skip_if: str) -> bool: |
174 | 171 | return eval(skip_if, {"sys": sys, "os": os, "pytest": pytest, "platform": platform}) |
175 | 172 |
|
176 | 173 |
|
177 | | -if Version(pytest.__version__) >= Version("7.0.0rc1"): |
178 | | - |
179 | | - def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlTestFile]: |
180 | | - if file_path.suffix in {".yaml", ".yml"} and file_path.name.startswith(("test-", "test_")): |
181 | | - return YamlTestFile.from_parent(parent, path=file_path, fspath=None) |
182 | | - return None |
183 | | - |
184 | | -else: |
185 | | - |
186 | | - def pytest_collect_file(path: py.path.local, parent: Node) -> Optional[YamlTestFile]: # type: ignore[misc] |
187 | | - if path.ext in {".yaml", ".yml"} and path.basename.startswith(("test-", "test_")): |
188 | | - return YamlTestFile.from_parent(parent, fspath=path) |
189 | | - return None |
| 174 | +def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlTestFile]: |
| 175 | + if file_path.suffix in {".yaml", ".yml"} and file_path.name.startswith(("test-", "test_")): |
| 176 | + return YamlTestFile.from_parent(parent, path=file_path, fspath=None) |
| 177 | + return None |
190 | 178 |
|
191 | 179 |
|
192 | 180 | def pytest_addoption(parser: Parser) -> None: |
|
0 commit comments