Skip to main content

Testing

SimSwarm has a backend pytest suite and a frontend Vitest suite. Neither requires external services — the backend runs against in-memory SQLite.

Backend

pytest

Configuration (pyproject.toml):

  • asyncio_mode = "auto" — tests are written with pytest-asyncio and async functions are collected automatically (no per-test decorator needed).
  • testpaths = ["tests"].
  • Coverage is configured with a fail_under = 90 gate over the saas package (pytest-cov); saas/main.py and saas/workers/celery_app.py are omitted, along with tests/migrations.

Test database

Tests use in-memory SQLite via aiosqlite (TEST_DATABASE_URL = "sqlite+aiosqlite://" in tests/conftest.py) — no Postgres needed. The schema is created from Base.metadata per engine fixture and dropped afterward.

Fixtures (tests/conftest.py)

FixtureWhat it provides
clientAn async httpx AsyncClient wired to the app via ASGITransport, with get_session overridden to the test SQLite session.
db_sessionAn AsyncSession against the in-memory engine.
auth_headersRegisters a test user and returns Authorization: Bearer … headers (plus the user id).
funded_userThe authenticated user's id. (Named for legacy reasons — there are no credits in the OSS build, so jobs are free.)
seeded_routingSeeds the ModelRouting rows (small/medium/large) that job creation requires.

An autouse reset_rate_limiter fixture resets the shared slowapi limiter before and after every test so counters don't leak across cases.

Frontend

cd frontend && npm test # vitest run
cd frontend && npm run test:coverage

npm test runs Vitest once (vitest run). npm run test:coverage runs with the coverage reporter. There is also a Playwright end-to-end suite (npm run test:e2e).

Linting

Backend code is linted with Ruff at line length 100 ([tool.ruff] in pyproject.toml). Run both test suites and lint before opening a PR.

No fake data

Never generate fake or mock data for demos or feature testing — use only real data from actual simulation runs. The one exception is unit/integration test mocks, which are fine. This keeps demo content and feature validation honest.