|
1 | 1 | """Pytest configuration for the json infra tests.""" |
2 | 2 |
|
3 | | -import json |
4 | 3 | import os |
5 | 4 | import shutil |
6 | 5 | import tarfile |
|
9 | 8 | from typing import ( |
10 | 9 | Callable, |
11 | 10 | Final, |
12 | | - Generator, |
13 | 11 | Optional, |
14 | 12 | Self, |
15 | 13 | Set, |
|
22 | 20 | from _pytest.nodes import Item |
23 | 21 | from filelock import FileLock |
24 | 22 | from git.exc import GitCommandError, InvalidGitRepositoryError |
25 | | -from pytest import Collector, File, Session, StashKey, fixture |
| 23 | +from pytest import Collector, Session, StashKey, fixture |
26 | 24 | from requests_cache import CachedSession |
27 | 25 | from requests_cache.backends.sqlite import SQLiteCache |
28 | 26 |
|
29 | 27 | from . import TEST_FIXTURES |
30 | | -from .helpers import ALL_FIXTURE_TYPES |
| 28 | +from .helpers import FixturesFile |
31 | 29 |
|
32 | 30 | try: |
33 | 31 | from xdist import get_xdist_worker_id |
@@ -299,35 +297,3 @@ def pytest_collect_file( |
299 | 297 | if file_path.suffix == ".json": |
300 | 298 | return FixturesFile.from_parent(parent, path=file_path) |
301 | 299 | return None |
302 | | - |
303 | | - |
304 | | -class FixturesFile(File): |
305 | | - """Single JSON file containing fixtures.""" |
306 | | - |
307 | | - def collect( |
308 | | - self: Self, |
309 | | - ) -> Generator[Item | Collector, None, None]: |
310 | | - """Collect test cases from a single JSON fixtures file.""" |
311 | | - with open(self.path, "r") as file: |
312 | | - try: |
313 | | - loaded_file = json.load(file) |
314 | | - except Exception: |
315 | | - return # Skip *.json files that are unreadable. |
316 | | - if not isinstance(loaded_file, dict): |
317 | | - return |
318 | | - for key, test_dict in loaded_file.items(): |
319 | | - if not isinstance(test_dict, dict): |
320 | | - continue |
321 | | - for fixture_type in ALL_FIXTURE_TYPES: |
322 | | - if not fixture_type.is_format(test_dict): |
323 | | - continue |
324 | | - name = key |
325 | | - if "::" in name: |
326 | | - name = name.split("::")[1] |
327 | | - yield fixture_type.from_parent( # type: ignore |
328 | | - parent=self, |
329 | | - name=name, |
330 | | - test_file=str(self.path), |
331 | | - test_key=key, |
332 | | - test_dict=test_dict, |
333 | | - ) |
0 commit comments