Testing
Clawbolt uses pytest with FastAPI’s TestClient. Tests require a running PostgreSQL instance with a clawbolt_test database.
Run all tests
Section titled “Run all tests”uv sync --all-extrasuv run pytest -vLint and format
Section titled “Lint and format”uv run ruff check backend/ tests/uv run ruff format --check backend/ tests/Type checking
Section titled “Type checking”uv run ty check --python .venv backend/ tests/Database setup
Section titled “Database setup”Tests connect to postgresql://clawbolt:clawbolt@localhost:5432/clawbolt_test. The conftest handles table creation and per-test transaction rollback automatically.
# Create the test database (one-time setup)createdb -U clawbolt clawbolt_testTest infrastructure
Section titled “Test infrastructure”Store isolation
Section titled “Store isolation”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.
Mock factories
Section titled “Mock factories”All external services are mocked in tests. Mock factories live in tests/mocks/:
| Mock | What it replaces |
|---|---|
| Telegram | Telegram Bot API calls |
| LLM | any-llm acompletion calls |
| Dropbox/Drive | Cloud storage operations |
| Storage | MockStorageBackend for file operations |
Auth override
Section titled “Auth override”The get_current_user dependency is overridden in tests to return a fixed test user, bypassing authentication.
Definition of done
Section titled “Definition of done”Every change should pass all checks:
uv run pytest -v # tests passuv run ruff check backend/ tests/ # lint passesuv run ruff format --check backend/ tests/ # format passesuv run ty check --python .venv backend/ tests/ # type checking passesBug fixes must include regression tests.