Skip to content

Testing

Clawbolt uses pytest with FastAPI’s TestClient. Tests require a running PostgreSQL instance with a clawbolt_test database.

Terminal window
uv sync --all-extras
uv run pytest -v
Terminal window
uv run ruff check backend/ tests/
uv run ruff format --check backend/ tests/
Terminal window
uv run ty check --python .venv backend/ tests/

Tests connect to postgresql://clawbolt:clawbolt@localhost:5432/clawbolt_test. The conftest handles table creation and per-test transaction rollback automatically.

Terminal window
# Create the test database (one-time setup)
createdb -U clawbolt clawbolt_test

The _isolate_file_stores autouse fixture patches settings.data_dir and calls reset_stores() to clear cached store singletons between tests. Each test runs in a database transaction that is rolled back after the test completes.

All external services are mocked in tests. Mock factories live in tests/mocks/:

MockWhat it replaces
TelegramTelegram Bot API calls
LLMany-llm acompletion calls
Dropbox/DriveCloud storage operations
StorageMockStorageBackend for file operations

The get_current_user dependency is overridden in tests to return a fixed test user, bypassing authentication.

Every change should pass all checks:

Terminal window
uv run pytest -v # tests pass
uv run ruff check backend/ tests/ # lint passes
uv run ruff format --check backend/ tests/ # format passes
uv run ty check --python .venv backend/ tests/ # type checking passes

Bug fixes must include regression tests.