Skip to content

Commit 7638b58

Browse files
test: add reset_singleton_state autouse fixture for module-level isolation
Required for test isolation when singleton state (_shared_client, _shared_client_refcount, _shared_client_lock) is added to __init__.py in a later task. Uses hasattr guards so it is safe to land before the implementation exists. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent 2f2c5fb commit 7638b58

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@ def mock_cache_home(tmp_path, monkeypatch):
3838
)
3939
return tmp_path
4040

41+
42+
@pytest.fixture(autouse=True)
43+
def reset_singleton_state():
44+
"""Reset module-level singleton state before each test.
45+
46+
Required for test isolation: module-level variables persist across
47+
tests in the same pytest session. Without this reset, singleton tests
48+
bleed state into each other.
49+
50+
Uses hasattr guards because the singleton attributes don't exist yet
51+
until Task 4 adds them to __init__.py. Guards make this fixture safe
52+
to land before the implementation.
53+
"""
54+
import amplifier_module_provider_github_copilot as mod
55+
56+
# Guard: attributes may not exist until implementation is added (Task 4)
57+
if hasattr(mod, "_shared_client"):
58+
mod._shared_client = None # type: ignore[attr-defined]
59+
if hasattr(mod, "_shared_client_refcount"):
60+
mod._shared_client_refcount = 0 # type: ignore[attr-defined]
61+
if hasattr(mod, "_shared_client_lock"):
62+
mod._shared_client_lock = None # type: ignore[attr-defined]
63+
yield
64+
if hasattr(mod, "_shared_client"):
65+
mod._shared_client = None # type: ignore[attr-defined]
66+
if hasattr(mod, "_shared_client_refcount"):
67+
mod._shared_client_refcount = 0 # type: ignore[attr-defined]
68+
if hasattr(mod, "_shared_client_lock"):
69+
mod._shared_client_lock = None # type: ignore[attr-defined]
70+
71+
4172
# Fix for Windows asyncio cleanup issues causing KeyboardInterrupt
4273
# See: https://github.com/pytest-dev/pytest-asyncio/issues/671
4374
if sys.platform == "win32":

0 commit comments

Comments
 (0)