python-testing

Provide pytest fixtures, markers, async patterns, and mocks for FastAPI testing.

4|Updated Dec 5, 2025
One-click install
npx skills add https://github.com/aaaa47080/stock_agent --skill python-testing-aaaa47080
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/aaaa47080/stock_agent/tree/main/.opencode/skills/python-testing
Command: npx skills add https://github.com/aaaa47080/stock_agent --skill python-testing-aaaa47080

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pytest testing for FastAPI projects often lacks standardized patterns, leading to boilerplate and flaky tests. This Skill provides clear guidance on fixtures, markers, async testing, and mocking to create reliable, reusable test suites.

Core Features & Use Cases

  • Fixtures: Reusable setup for tests, including database fixtures and test clients.
  • Markers: Categorize tests (unit, integration, e2e) and control execution.
  • Async Testing: Support for testing async FastAPI endpoints with asyncio.
  • Mocking: Isolate external calls with mocks to speed tests and improve reliability.

Quick Start

Run your test suite with pytest using a standard setup and the provided patterns to ensure fast and reliable tests.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I structure pytest fixtures for FastAPI database interactions?

Pytest fixtures for FastAPI provide reusable setup for database sessions and test clients, isolating database interactions to ensure test state remains clean and reliable across unit and integration tests.

What's the best way to test async FastAPI endpoints with pytest?

Testing async FastAPI endpoints requires asyncio testing patterns that handle asynchronous request execution properly, preventing flaky tests by managing event loops and async database transactions effectively.

How do I isolate external calls in FastAPI tests using mocking?

Mocking in FastAPI tests isolates external API calls by replacing them with controlled mock objects, speeding up test execution and improving reliability by avoiding network dependencies and external service flakiness.

Can I categorize FastAPI tests using custom pytest markers?

Custom pytest markers categorize FastAPI tests into unit, integration, and end-to-end groups, allowing you to control execution scope and selectively run specific test categories during development or CI pipelines.

Why are my FastAPI pytest tests flaky and how do I fix them?

FastAPI pytest tests become flaky from unmanaged async state and external dependencies; standardizing fixtures, using async patterns, and mocking external calls eliminate unpredictable test failures and ensure consistent execution.