Files
animaltrack/tests/conftest.py
Petru Paler 7d7cd2bb57 feat: add migration framework with FastMigrate integration
- Add migrations.py with create_migration, run_migrations, get_db_version
- Implement CLI migrate and create-migration commands
- Use FastMigrate's sequential 0001-*.sql naming convention
- Add comprehensive unit, integration, and E2E tests (35 tests)
- Add fresh_db_path and temp_migrations_dir test fixtures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 18:25:28 +00:00

51 lines
1.4 KiB
Python

# ABOUTME: Pytest configuration and fixtures for AnimalTrack tests.
# ABOUTME: Provides database fixtures, test clients, and common utilities.
import os
import tempfile
import pytest
@pytest.fixture
def temp_migrations_dir(tmp_path):
"""Create a temporary migrations directory for testing."""
migrations_path = tmp_path / "migrations"
migrations_path.mkdir()
return migrations_path
@pytest.fixture
def fresh_db_path(tmp_path):
"""Provide a path for a non-existent database file.
Unlike temp_db_path, this does not create the file - it just provides
a path. This is needed for fastmigrate which expects to create the db.
"""
db_path = tmp_path / "test.db"
yield db_path
# Cleanup
if db_path.exists():
db_path.unlink()
# Also clean up WAL files if they exist
for suffix in ["-shm", "-wal", "-journal"]:
wal_path = db_path.with_suffix(db_path.suffix + suffix)
if wal_path.exists():
wal_path.unlink()
@pytest.fixture
def temp_db_path():
"""Create a temporary database file path for testing."""
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
db_path = f.name
yield db_path
# Cleanup
if os.path.exists(db_path):
os.unlink(db_path)
# Also clean up WAL files if they exist
for suffix in ["-shm", "-wal", "-journal"]:
wal_path = db_path + suffix
if os.path.exists(wal_path):
os.unlink(wal_path)