backend-tests

Write and organize backend Python tests across unit, integration, API, and migration layers.

49|11|Updated Jul 31, 2026
One-click install
npx skills add https://github.com/vstorm-co/agenticos --skill backend-tests-vstorm-co
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backend-tests
Source: https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/backend-tests
Command: npx skills add https://github.com/vstorm-co/agenticos --skill backend-tests-vstorm-co

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Deciding where a backend test belongs and why the suite fails is hard in a four-layer test architecture with a 100% coverage gate on the platform layer. This Skill guides writing unit, integration, API, and migration tests for a FastAPI/Postgres backend using anyio, and diagnoses coverage-gate and test-suite failures. ## Core Features & Use Cases - Layer Selection: Routes each test to the right layer — unit tests with mocked repositories, integration tests against a real Postgres for schema guarantees, API tests for route permission wiring, and E2E via a separate skill. - anyio Conventions: Enforces pytestmark = pytest.mark.anyio instead of pytest-asyncio, with the correct fixtures (client, mock_db_session, mock_redis) from conftest. - Coverage Gate Diagnostics: Explains the 100% platform-layer gate, the two ways a module silently drops out of coverage, and how to read gaps as untested branches. - Use Case: A bug fix needs a regression test — the Skill helps you name the behaviour, assert the consequence, cover the refusal path, and place the test in the correct layer so make test passes. ## Quick Start Write a unit test for the agent registry service that verifies publishing an agent with an unknown capability is refused.

Frequently Asked Questions about backend-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write async pytest tests with anyio instead of pytest-asyncio?▼

Set pytestmark = pytest.mark.anyio at the module top and write plain async test functions. There is no asyncio_mode or @pytest.mark.asyncio; the anyio_backend fixture in conftest pins asyncio because that is what uvicorn uses.

How to test FastAPI routes and permissions with httpx AsyncClient?▼

Use the client fixture, an httpx.AsyncClient over ASGITransport(app=app), never Starlette's TestClient. Override get_auth_context with a synthetic caller holding or missing one permission, then assert the route returns 403.

When should I use integration tests against a real Postgres database?▼

Use integration tests when the assertion is about the schema: CHECK constraints, partial unique indexes, cascades, NOT NULL on org columns, and tenant isolation. A mock cannot tell you whether a constraint rejects a row.

Why does coverage not measure my new Python module?▼

Coverage include only reports files that were imported; a module nothing imports is not measured at all rather than measured at 0%. Also use include globs, not source, since source silently ignores file paths.

How do I fix a failing 100% coverage gate in CI?▼

Run make test-cov and open backend/htmlcov/index.html; show_missing and skip_covered make the terminal report list only the gaps. Read them as untested branches — the honest fix for an unreachable branch is usually deleting it.