Bluefox Stack

Test infrastructure
for FastAPI apps

Real Postgres via testcontainers. Async factories. SAVEPOINT isolation. Safety gates that prevent tests from touching production. Three lines to set up.

Your entire test setup
conftest.py
from bluefox_test import bluefox_test_setup
from app.models import Base

globals().update(bluefox_test_setup(base=Base))

What you get

Real databases

Postgres and Redis via testcontainers. No mocks, no SQLite. Your tests hit the same engine as production.

Async factories

Declare factories with Faker fields, register them once. Get create_user, create_todo fixtures everywhere.

SAVEPOINT isolation

Each test runs inside a nested transaction. After the test: ROLLBACK. Sub-millisecond cleanup, full isolation.

Safety gates

Host whitelist, test_ database prefix enforcement, network guard. Tests cannot touch production by accident.

Write tests like this

Factories return real database objects. No manual setup, no teardown. Every test starts clean.

auth/tests/factories.py
from bluefox_test import BaseFactory, Faker, register
from auth.models import User

class UserFactory(BaseFactory):
    class Meta:
        model = User

    email = Faker("email")
    name = Faker("name")

create_user = register(UserFactory)
auth/tests/test_routes.py
async def test_login(client, create_user):
    user = await create_user(email="hugo@example.com")

    response = await client.post("/auth/login", json={
        "email": "hugo@example.com",
        "password": "mypassword",
    })
    assert response.status_code == 200