Skip to content

Latest commit

 

History

History
96 lines (73 loc) · 2.06 KB

README.md

File metadata and controls

96 lines (73 loc) · 2.06 KB

Testing Guide

Overview

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

Running Tests

Basic test run:

pytest

With coverage:

pytest --cov=app tests/

With verbose output:

pytest -v

Test Structure

Fixtures

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

Settings in Tests

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"}

File Operations

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

Adding New Tests

  1. Create test files in the appropriate directory
  2. Use the provided fixtures for consistent setup/teardown
  3. Follow the existing patterns for settings usage
  4. Clean up any created files in teardown
  5. Use type hints and docstrings
  6. Test both success and error cases

Best Practices

  1. Use descriptive test names
  2. One assertion per test when possible
  3. Use fixtures for setup/teardown
  4. Mock external dependencies
  5. Test edge cases and errors
  6. Keep tests focused and simple
  7. Use appropriate assert statements
  8. Clean up test data