Skip to content

Commit 0110511

Browse files
committed
fix(tests): json files cache
1 parent dde7532 commit 0110511

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

tests/json_infra/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ def pytest_runtest_teardown(item: Item, nextitem: Item) -> None:
309309
same type or does not belong to the same fixtures file.
310310
"""
311311
if isinstance(item, FixtureTestItem):
312-
if not isinstance(nextitem, FixtureTestItem):
312+
if (
313+
nextitem is None
314+
or not isinstance(nextitem, FixtureTestItem)
315+
or item.fixtures_file != nextitem.fixtures_file
316+
):
313317
item.fixtures_file.clear_data_cache()
314-
else:
315-
if item.fixtures_file != nextitem.fixtures_file:
316-
item.fixtures_file.clear_data_cache()

tests/json_infra/helpers/fixtures.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def data(self) -> Dict[str, Any]:
7575

7676
def clear_data_cache(self) -> None:
7777
"""Drop the data cache."""
78-
del self.data
78+
self.__dict__.pop("data", None)
7979

8080
def collect(
8181
self: Self,
@@ -85,22 +85,21 @@ def collect(
8585
loaded_file = self.data
8686
except Exception:
8787
return # Skip *.json files that are unreadable.
88-
if not isinstance(loaded_file, dict):
89-
return
90-
for key, test_dict in loaded_file.items():
91-
if not isinstance(test_dict, dict):
92-
continue
93-
for fixture_type in ALL_FIXTURE_TYPES:
94-
if not fixture_type.is_format(test_dict):
88+
if isinstance(loaded_file, dict):
89+
for key, test_dict in loaded_file.items():
90+
if not isinstance(test_dict, dict):
9591
continue
96-
name = key
97-
if "::" in name:
98-
name = name.split("::")[1]
99-
yield fixture_type.from_parent( # type: ignore
100-
parent=self,
101-
name=name,
102-
test_file=str(self.path),
103-
test_key=key,
104-
)
92+
for fixture_type in ALL_FIXTURE_TYPES:
93+
if not fixture_type.is_format(test_dict):
94+
continue
95+
name = key
96+
if "::" in name:
97+
name = name.split("::")[1]
98+
yield fixture_type.from_parent( # type: ignore
99+
parent=self,
100+
name=name,
101+
test_file=str(self.path),
102+
test_key=key,
103+
)
105104
# Make sure we don't keep anything from collection in memory.
106105
self.clear_data_cache()

0 commit comments

Comments
 (0)