Fix Windows file locking in repository tests

This commit is contained in:
2025-11-16 20:13:43 +00:00
parent 3961b0e696
commit 7fbbf1e387

View File

@@ -14,7 +14,8 @@ from py_dvt_ate.data.repository import SQLiteRepository
@pytest.fixture @pytest.fixture
def temp_db(): def temp_db():
"""Create a temporary database for testing.""" """Create a temporary database for testing."""
with tempfile.TemporaryDirectory() as tmpdir: # Use ignore_cleanup_errors=True for Windows file locking issues
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir:
db_path = Path(tmpdir) / "test.db" db_path = Path(tmpdir) / "test.db"
yield db_path yield db_path
@@ -27,6 +28,7 @@ def repository(temp_db):
yield repo yield repo
# Ensure all connections and file handles are closed before cleanup # Ensure all connections and file handles are closed before cleanup
# This is critical on Windows to prevent PermissionError # This is critical on Windows to prevent PermissionError
repo.close()
del repo del repo
gc.collect() gc.collect()