CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/pytest-api-testing

Pytest patterns for Python APIs -- httpx AsyncClient, conftest fixtures, database isolation, parametrize edge cases, error response testing, auth flows, factory fixtures

99

1.23x
Quality

99%

Does it follow best practices?

Impact

100%

1.23x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

test-fastapi-with-database.jsonverifiers/

{
  "instruction": "Write pytest tests for a FastAPI blog API that uses SQLAlchemy with SQLite. Endpoints: POST /api/posts (create), GET /api/posts (list with pagination), GET /api/posts/{id} (detail), DELETE /api/posts/{id} (delete). Set up proper database fixtures with test isolation.",
  "relevant_when": "Agent writes tests for a FastAPI app that uses SQLAlchemy or a database",
  "context": "Proactively verify that agents set up proper database fixtures with cleanup, use dependency overrides for the database session, and ensure test isolation.",
  "sources": [
    {
      "type": "file",
      "filename": "skills/pytest-api-testing/SKILL.md",
      "tile": "tessl-labs/pytest-api-testing"
    }
  ],
  "checklist": [
    {
      "name": "httpx-async-client",
      "rule": "Tests use httpx.AsyncClient with ASGITransport to test the FastAPI app",
      "relevant_when": "Agent sets up a test client for FastAPI"
    },
    {
      "name": "database-fixture-with-cleanup",
      "rule": "Tests include a database fixture that either uses transaction rollback after each test, truncates tables before each test, or uses a fresh in-memory database per test. The fixture must ensure tests do not leak state.",
      "relevant_when": "Agent sets up database fixtures for testing"
    },
    {
      "name": "dependency-override-for-db",
      "rule": "Tests use FastAPI's app.dependency_overrides to inject the test database session, rather than monkeypatching imports or using environment variables alone",
      "relevant_when": "Agent writes tests for a FastAPI app that uses dependency injection for database access"
    },
    {
      "name": "fixture-scope-correct",
      "rule": "The database engine/schema fixture uses session scope (created once), while the cleanup/reset fixture uses function scope (runs per test). The client fixture is function-scoped, not session-scoped.",
      "relevant_when": "Agent defines database and client fixtures"
    },
    {
      "name": "conftest-organization",
      "rule": "Database fixtures, client fixture, and helper fixtures are defined in tests/conftest.py, not in individual test files",
      "relevant_when": "Agent creates test fixtures"
    },
    {
      "name": "tests-crud-operations",
      "rule": "Tests cover create, read (list and detail), and delete operations, verifying both the status code and the response body for each",
      "relevant_when": "Agent writes tests for CRUD endpoints"
    },
    {
      "name": "tests-persistence",
      "rule": "At least one test verifies persistence: create a resource via POST, then retrieve it via GET and verify the data matches",
      "relevant_when": "Agent writes tests for endpoints that create data"
    },
    {
      "name": "clears-dependency-overrides",
      "rule": "The client fixture clears app.dependency_overrides after the test (in the teardown/cleanup phase) to prevent leaking overrides",
      "relevant_when": "Agent uses dependency_overrides in test fixtures"
    }
  ]
}

tile.json