python-testing-patterns
Learn to structure Python tests using pytest, fixtures, parameterization, and mocking techniques. This skill covers unit and integration testing, test isolation, the AAA pattern, and debugging strategies to establish reliable test infrastructure.
Python Testing Patterns helps you set up comprehensive test suites using pytest fixtures, mocking, and TDD best practices.
AI-generated summary based on this skill's SKILL.md
Install
HermeticOrmus/LibreUIUX-Claude-Code/python-testing-patterns · repository language: Shell
git clone https://github.com/HermeticOrmus/LibreUIUX-Claude-Code
cp -r LibreUIUX-Claude-Code/plugins/python-development/skills/python-testing-patterns ~/.claude/skills/python-testing-patternsnpx skillfed install HermeticOrmus/LibreUIUX-Claude-Code/python-testing-patternsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to write pytest tests in Python?
python-testing-patterns teaches you to write pytest tests by organizing test functions with clear naming conventions (test_* prefix), using the AAA pattern (Arrange, Act, Assert), and structuring assertions with descriptive messages. Start with simple unit tests that verify single behaviors, then progress to fixtures for setup/teardown and parameterization for testing multiple input scenarios efficiently.
What are pytest fixtures and how do setup/teardown work?
python-testing-patterns covers pytest fixtures as reusable test components that handle setup and teardown automatically. Fixtures use the @pytest.fixture decorator and can yield values to tests or clean up resources afterward. The skill explains scope levels (function, class, module, session), dependency injection patterns, and how conftest.py enables sharing fixtures across test files.
How do you mock external dependencies in Python unit tests?
python-testing-patterns demonstrates mocking external dependencies using unittest.mock and pytest plugins. Learn to replace real API calls, database connections, and services with controlled mock objects, verify mock interactions with assert_called_with, and use monkeypatch for environment variables and module attributes. This isolates tests from external systems.
What is test-driven development (TDD) and how to implement it?
python-testing-patterns explains TDD as writing tests before implementation code, following the red-green-refactor cycle. Start by writing a failing test, implement minimal code to pass it, then refactor. This skill shows how TDD improves design, catches bugs early, and creates living documentation through comprehensive test coverage.
How can you test async code and database operations with pytest?
python-testing-patterns covers async testing using pytest-asyncio for coroutines, fixtures with async setup, and testing SQLAlchemy operations with in-memory databases or fixtures. Learn integration testing patterns for database transactions, rollback strategies, and how to test async/await workflows alongside synchronous code.
How do you measure code coverage and improve test quality?
python-testing-patterns teaches coverage measurement using pytest-cov to identify untested code paths, interpret coverage reports, and set quality gates. The skill explains coverage limitations, strategies for meaningful metrics beyond percentages, and how to use parametrized tests and property-based testing with Hypothesis to strengthen test suites.
SKILL.md
rendered from the published skill — quoted content, verbatim
Python Testing Patterns
Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.
When to Use This Skill
- Writing unit tests for Python code
- Setting up test suites and test infrastructure
- Implementing test-driven development (TDD)
- Creating integration tests for APIs and services
- Mocking external dependencies and services
- Testing async code and concurrent operations
- Setting up continuous testing in CI/CD
- Implementing property-based testing
- Testing database operations
- Debugging failing tests
Core Concepts
1. Test Types
- Unit Tests: Test individual functions/classes in isolation
- Integration Tests: Test interaction between components
- Functional Tests: Test complete features end-to-end
- Performance Tests: Measure speed and resource usage
2. Test Structure (AAA Pattern)
-
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
plugins/python-development/skills/python-testing-patterns/SKILL.md