litefs-testing

majiayu000's avatarfrom majiayu000

Testing patterns for litefs-py and litefs-django. Use when writing tests, setting up fixtures, understanding test organization, or configuring pytest marks. Triggers: test, pytest, unit test, integration test, property-based testing, hypothesis, fixtures, in-memory adapters.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 5, 2026

When & Why to Use This Skill

This Claude skill provides comprehensive testing strategies and patterns specifically designed for litefs-py and litefs-django applications. It enables developers to implement robust unit, integration, and property-based tests using pytest, ensuring reliable database replication and configuration management through specialized in-memory adapters and strict isolation rules.

Use Cases

  • Architecting a multi-layered test suite for LiteFS projects, separating fast unit tests from Docker-based integration tests.
  • Utilizing in-memory adapters like InMemoryProcessRunner and FakePrimaryDetector to test domain logic without external dependencies or FUSE requirements.
  • Implementing property-based testing with Hypothesis to ensure configuration generation, YAML parsing, and path validation are bug-free.
  • Defining CI/CD workflows that optimize developer feedback loops by running fast unit tests on every pull request while reserving heavy integration tests for the main branch.
  • Setting up pytest fixtures and custom marks to manage complex LiteFS test environments and validate replication behavior effectively.
namelitefs-testing
descriptionTesting patterns for litefs-py and litefs-django. Use when writing tests, setting up fixtures, understanding test organization, or configuring pytest marks. Triggers: test, pytest, unit test, integration test, property-based testing, hypothesis, fixtures, in-memory adapters.

LiteFS Testing Strategy

Project-specific testing patterns for litefs-py and litefs-django.

When to Use

  • Writing tests for LiteFS-related code
  • Setting up test fixtures
  • Understanding test organization

Test Organization

# By category
pytest -m unit           # Fast, no LiteFS process
pytest -m integration    # With Docker + FUSE
pytest -m property       # Property-based tests

Test Directory Structure

tests/
├── unit/                    # No I/O, no subprocess
│   ├── domain/              # Pure domain logic (settings, config)
│   ├── usecases/            # Use case tests with in-memory adapters
│   └── conftest.py          # In-memory adapter fixtures
├── integration/             # Requires Docker + FUSE
│   ├── test_backend.py
│   └── test_replication.py
└── conftest.py              # Shared fixtures

CI Strategy

  • Unit tests: Run on all PRs (fast, no Docker)
  • Integration tests: Run on main branch only (requires Docker + FUSE)
  • Local testing: Docker Compose setup mirrors integration CI

Test Isolation Rules

Unit tests (tests/unit/) must NOT:

  • Spawn subprocesses or call LiteFS binary
  • Access filesystem beyond temp directories
  • Require FUSE or Docker

Unit tests SHOULD use:

  • In-memory adapter fixtures:
    • in_memory_process_runner → InMemoryProcessRunner
    • in_memory_config_writer → InMemoryConfigWriter
    • fake_primary_detector → FakePrimaryDetector

In-Memory Adapter Pattern

# tests/unit/conftest.py
@pytest.fixture
def in_memory_process_runner():
    return InMemoryProcessRunner()

# tests/unit/usecases/test_process_manager.py
def test_start_litefs(in_memory_process_runner):
    manager = ProcessManager(runner=in_memory_process_runner)
    manager.start()
    assert in_memory_process_runner.started is True

Property-Based Testing (Hypothesis)

Use for config generation and settings validation:

uv run pytest -m property -v

When to use:

Pattern Property to Test Example
Round-trip parse(generate(x)) == x Config YAML generation
Invariants Bounds always hold Path validation
Idempotence f(f(x)) == f(x) Settings normalization
from hypothesis import given, strategies as st

@pytest.mark.property
@given(mount_path=st.text(min_size=1).filter(lambda x: x.startswith("/")))
def test_config_includes_mount_path(mount_path):
    settings = LiteFSSettings(mount_path=mount_path)
    config = ConfigGenerator().generate(settings)
    assert mount_path in config