python-testing

Write and organize Python tests using pytest fixtures, parametrization, mocking, and coverage analysis.

Updated Jun 12, 2026
One-click install
npx skills add https://github.com/bilacchi/agents-skills --skill python-testing-bilacchi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/bilacchi/agents-skills/tree/main/skills/python-testing
Command: npx skills add https://github.com/bilacchi/agents-skills --skill python-testing-bilacchi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing pytest's fixture system, parametrization, mocking patterns, and coverage tooling, which developers often implement inconsistently or incorrectly. ## Core Features & Use Cases - Fixtures and Parametrization: Reusable setup/teardown with scoped fixtures and data-driven tests via @pytest.mark.parametrize. - Mocking and Async Testing: Patterns for unittest.mock, pytest-mock, and async test functions with pytest-asyncio. - Coverage and Organization: Coverage reporting with fail-under thresholds, test markers, conftest.py setup, and directory structure guidance. - Use Case: When building a new FastAPI service, use this Skill to scaffold unit and integration tests with database fixtures, mocked external services, and an 80% coverage gate. ## Quick Start Write pytest tests for my Python module using fixtures, parametrized cases, and coverage reporting.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I write parametrized tests in pytest?▼

Use @pytest.mark.parametrize with argument names and a list of value tuples to run one test function against multiple inputs. You can add ids to label each case, making failures easier to identify in output.

How to use pytest fixtures for database testing?▼

Define a fixture that creates an in-memory SQLite session, yields it to the test, and closes it afterward. Choose a scope such as function, class, module, or session depending on how often setup should run.

What is the difference between unittest.mock and pytest-mock?▼

unittest.mock provides Mock, patch, and MagicMock from the standard library, while pytest-mock wraps these in a mocker fixture with cleaner syntax. Both let you stub dependencies and assert on call counts and arguments.

Does pytest support async test functions?▼

Yes, with the pytest-asyncio plugin you mark coroutine tests with @pytest.mark.asyncio and can define async fixtures that yield connected clients. Without the plugin, async tests are skipped or fail.

How do I enforce a minimum test coverage threshold?▼

Run pytest with --cov=src and --cov-fail-under=80, or set these in pytest.ini or pyproject.toml addopts. The test run fails if coverage drops below the configured percentage.

When should I use hypothesis instead of parametrized tests?▼

Use hypothesis for property-based testing when you want generated inputs to verify invariants like commutativity or idempotence across many cases. Use parametrize when you have specific known inputs and expected outputs.