python-testing

Automate pytest workflows for Python projects with fixtures, mocking, and async tests.

1|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/anicdh/agstack --skill python-testing-anicdh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/anicdh/agstack/tree/main/.claude/skills/python/python-testing
Command: npx skills add https://github.com/anicdh/agstack --skill python-testing-anicdh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Automates best practices for pytest-based testing in Python projects, helping developers structure tests, reuse fixtures, and validate async code with HTTP clients, reducing boilerplate and preventing flaky tests.

Core Features & Use Cases

  • Test Structure & Organization: Clear layout of tests, modular modules, and consistent naming conventions.
  • Fixtures & Reuse: Centralized fixtures via conftest.py for fast, reliable test setup.
  • Async & Mocking: Patterns for testing async code with httpx.AsyncClient and mocking dependencies to isolate units.

Quick Start

Run pytest tests/ to execute the unit and integration tests described above.

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 tests and fixtures to reduce boilerplate in Python backend services?

To structure pytest tests effectively, you should organize tests into modular modules with consistent naming conventions and centralize reusable test setup via conftest.py fixtures. This approach reduces boilerplate and prevents flaky tests across backend services.

How do I test async code with httpx.AsyncClient in pytest?

You can test async code with httpx.AsyncClient in pytest by applying dedicated async testing patterns. These patterns integrate with pytest fixtures to validate asynchronous HTTP client interactions and isolate units through mocking.

What is the best way to parametrize test scenarios and handle expected exceptions in pytest?

The best way to parametrize test scenarios in pytest is using parametrized test functions, while expected exceptions should be validated using the pytest.raises context manager. This enforces robust testing patterns across varied inputs and edge cases.

Does pytest testing support both unit and integration tests for Python apps?

Yes, pytest testing supports both unit and integration tests for Python apps. The workflow covers everything from isolated unit tests with mocked dependencies to end-to-end router tests across backend services.

Why do my pytest tests fail due to dependency isolation issues?

Pytest tests often fail from dependency isolation issues when units are not properly mocked. You can resolve this by applying mocking patterns to isolate units, ensuring that tests remain reliable and unaffected by external dependencies.

When do I need to specify fixture scope in pytest?

You need to specify fixture scope in pytest when centralizing fixtures via conftest.py to manage setup lifecycle. Enforcing fixture scope ensures fast, reliable test setup and prevents state leakage between test functions.