The test suite uses pytest and follows these principles:
- Tests are organized by module/functionality
- Fixtures are shared via conftest.py
- Settings are managed via Pydantic
- Test directories are created and cleaned up automatically
Basic test run:
pytest
With coverage:
pytest --cov=app tests/
With verbose output:
pytest -v
Key fixtures in conftest.py
:
@pytest.fixture
def test_dirs():
"""Creates and manages test directories."""
# Creates temporary upload/processed directories
# Cleans up after tests
@pytest.fixture
def config_paths():
"""Manages settings paths during tests."""
# Allows setting test paths
# Restores original paths after tests
@pytest.fixture
def test_video():
"""Creates test video files."""
# Helper for creating test videos
The application uses Pydantic settings. In tests:
from app.core.settings import settings
def test_example(test_dirs):
# Settings are automatically configured for tests
video_path = settings.upload_dir / "test.mp4"
assert settings.allowed_extensions == {"mp4", "avi", "mov", "mkv"}
Test file operations using the provided fixtures:
def test_file_upload(test_dirs, test_video):
video_id = "test-123"
video_path = test_video(video_id)
assert video_path.exists()
assert video_path.parent == settings.upload_dir
- Create test files in the appropriate directory
- Use the provided fixtures for consistent setup/teardown
- Follow the existing patterns for settings usage
- Clean up any created files in teardown
- Use type hints and docstrings
- Test both success and error cases
- Use descriptive test names
- One assertion per test when possible
- Use fixtures for setup/teardown
- Mock external dependencies
- Test edge cases and errors
- Keep tests focused and simple
- Use appropriate assert statements
- Clean up test data