Agent skill · software engineering · affaan-m

python-testing

Python testing best practices using pytest including fixtures, parametrization, mocking, coverage analysis, async testing, and test organization. Use when writing or improving Python tests.

Why this skill is useful

Provides specific pytest patterns and advanced testing techniques that the AI wouldn't reliably generate on its own.

What it needs

Requires pytest installed locally. About 5k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.

What this skill does

Python Testing This skill provides comprehensive Python testing patterns using pytest as the primary testing framework. Testing Framework Use pytest as the testing framework for its powerful features and clean syntax. Basic Test Structure Test Discovery pytest automatically discovers tests following these conventions: Files: test.py or test.py Functions: test Classes: Test (without init) Methods: test Fixtures Fixtures provide reusable test setup and teardown: Fixture Scopes Fixture Dependencies Parametrization Test multiple inputs with @pytest.mark.parametrize: Multiple Parameters Parametrize with IDs Test Markers Use markers for test categorization and selective execution: Run specific markers: Mocking Using unittest.mock pytest-mock Plugin Coverage Analysis Basic Coverage HTML Coverage Report Coverage Configuration Branch Coverage Async Testing Testing Async Functions Test Organization Directory Structure conftest.py Assertions Basic Assertions pytest Assertions with Better Error Messages Custom Assertion Messages Approximate Comparisons Exception Testing Test Helpers Property-Based Testing Using hypothesis for property-based testing: Best Practices 1. One assertion per test (when possible) 2. Use descriptive test names - describe what's being tested 3. Arrange-Act-Assert pattern - clear test structure 4. Use fixtures for setup - avoid duplication 5. Mock external dependencies - keep tests fast and isolated 6. Test edge cases - empty inputs, None, boundaries 7. Use parametrize - test multiple scenarios efficiently 8. Keep tests independent - no shared state between tests Running Tests When to Use This Skill Writing new Python tests Improving test coverage Setting up pytest infrastructure Debugging flaky tests Implementing integration tests Testing async Python code

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills affaan-m/python-testing--c8ce8c

View the source on GitHub

Browse the @skills marketplace