Skip to content

Commit 5e6203b

Browse files
committed
fix: update _patch_bases fixture to yield and clean up registries after tests
1 parent 070f575 commit 5e6203b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/integration/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def cleanup() -> None:
8989

9090

9191
@pytest.fixture(autouse=True)
92-
def _patch_bases(monkeypatch: MonkeyPatch) -> None: # pyright: ignore[reportUnusedFunction]
92+
def _patch_bases(monkeypatch: MonkeyPatch) -> Generator[None, None, None]: # pyright: ignore[reportUnusedFunction]
9393
"""Ensure new registry state for every test.
9494
9595
This prevents errors such as "Table '...' is already defined for
@@ -155,6 +155,24 @@ class NewBigIntAuditBase(
155155
monkeypatch.setattr(base, "BigIntBase", NewBigIntBase)
156156
monkeypatch.setattr(base, "BigIntAuditBase", NewBigIntAuditBase)
157157

158+
yield
159+
160+
# Clean up registries to prevent test pollution
161+
for base_class in [
162+
NewUUIDBase,
163+
NewUUIDAuditBase,
164+
NewUUIDv6Base,
165+
NewUUIDv6AuditBase,
166+
NewUUIDv7Base,
167+
NewUUIDv7AuditBase,
168+
NewNanoIDBase,
169+
NewNanoIDAuditBase,
170+
NewBigIntBase,
171+
NewBigIntAuditBase,
172+
]:
173+
base_class.registry.dispose()
174+
base_class.metadata.clear()
175+
158176

159177
@pytest.fixture(scope="session")
160178
def duckdb_engine(

0 commit comments

Comments
 (0)