pytest

Guides writing pytest fixtures, async tests, and parametrized cases for FastAPI projects.

Updated Sep 13, 2026
One-click install
npx skills add https://github.com/abdulazeezoj/monovella-poc --skill pytest-abdulazeezoj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/abdulazeezoj/monovella-poc/tree/main/.agents/skills/pytest
Command: npx skills add https://github.com/abdulazeezoj/monovella-poc --skill pytest-abdulazeezoj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-asyncio, httpx, aiosqlite, sqlmodel, fastapi, and includes references (resource) components.

What problem does it solve? It explains how this project's pytest suite is structured — fixtures, async test setup with pytest-asyncio, the isolated in-memory test database, and parametrize — so you can add tests, write fixtures, and debug confusing failures like coroutine objects handed to tests or state leaking between tests. ## Core Features & Use Cases - Async fixture guidance: Shows why async fixtures need @pytest_asyncio.fixture instead of plain @pytest.fixture, and what breaks when you mix them up. - Isolated test database pattern: Documents the in-memory SQLite engine with StaticPool, dependency overrides, and the autouse _prepare_database fixture that recreates the schema around every test. - Test design guides: Covers one-test-per-behavior structure, asserting status code plus response body shape, and using @pytest.mark.parametrize for repeated logic across inputs. - Use Case: You add a new endpoint and need tests for create, list, get, 404, and delete — follow the writing-a-good-test guide, then parametrize the invalid-payload cases that should all return 422. ## Quick Start Ask the assistant to write pytest tests for a new FastAPI endpoint following this project's fixture and isolation patterns.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I write async tests with pytest and FastAPI?

Write async def test functions that take the client fixture, an httpx.AsyncClient wrapping the app via ASGITransport. With asyncio_mode = "auto" in pyproject.toml, async test functions run as asyncio tests without needing @pytest.mark.asyncio on each one.

How do I test the same endpoint against multiple invalid payloads?

Use @pytest.mark.parametrize with a list of payloads and an ids list for readable failure names. One test function then asserts each invalid payload returns 422, avoiding near-duplicate test functions for every case.

Why does my async fixture return a coroutine object instead of a value?

The fixture was decorated with plain @pytest.fixture instead of @pytest_asyncio.fixture. Plain pytest fixtures do not await async generators, so the test receives the unawaited coroutine and fails later with an unrelated-looking AttributeError.

Why does a test pass alone but fail when the whole suite runs?

Database state is leaking between tests, usually because the schema-reset fixture's scope was widened to module or session. Keep the autouse _prepare_database fixture function-scoped so tables are created and dropped around every single test.

Does the test suite need a running Postgres database?

No. Tests run against an in-memory SQLite database built with StaticPool, and the fixtures never read DATABASE_URL from .env. This means pytest works with zero external services and a broken .env cannot break the suite.