Skip to content

Commit c951e50

Browse files
committed
Fix end to end tests
1 parent ad0ead6 commit c951e50

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

graphqler/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def compile_and_fuzz(path: str, url: str, input_config: dict | None = None) -> d
3838
compiler = Compiler(path, url)
3939
compiler.run()
4040

41+
stats = Stats()
42+
stats.set_file_paths(path)
43+
4144
fuzzer = Fuzzer(path, url)
4245
fuzzer.run()
4346

graphqler/utils/singleton.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ def getInstance(*args, **kwargs):
1111
# fresh_bucket = ObjectsBucket.__wrapped__(api)
1212
setattr(getInstance, "__wrapped__", myClass)
1313

14+
# Allow clearing the cached instance (useful for test isolation).
15+
setattr(getInstance, "reset", lambda: instances.pop(myClass, None))
16+
1417
return getInstance

tests/e2e/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(autouse=True, scope="function")
5+
def reset_singletons():
6+
"""Reset singleton instances before and after each test method.
7+
8+
When pytest-xdist uses fewer workers than test files, multiple test
9+
modules run sequentially in the same worker process. Singletons
10+
(Stats, ObjectsBucket, FEngine) would otherwise retain stale file
11+
paths and state from a previous test, causing FileNotFoundErrors and
12+
empty-bucket assertion failures.
13+
14+
Function scope is required because module-scoped fixtures are not
15+
reliably triggered between unittest.TestCase test files.
16+
"""
17+
from graphqler.utils.stats import Stats
18+
from graphqler.utils.objects_bucket import ObjectsBucket
19+
from graphqler.fuzzer.engine.fengine import FEngine
20+
21+
Stats.reset() # ty: ignore[unresolved-attribute]
22+
ObjectsBucket.reset() # ty: ignore[unresolved-attribute]
23+
FEngine.reset() # ty: ignore[unresolved-attribute]
24+
yield
25+
Stats.reset() # ty: ignore[unresolved-attribute]
26+
ObjectsBucket.reset() # ty: ignore[unresolved-attribute]
27+
FEngine.reset() # ty: ignore[unresolved-attribute]

0 commit comments

Comments
 (0)