python-testing
Learn pytest essentials and test-driven development patterns for Python projects. This skill covers fixtures, parametrization, mocking, and coverage strategies to build reliable test suites. Follow the red-green-refactor cycle and achieve 80%+ code coverage on your critical paths.
Python Testing teaches pytest fundamentals, TDD methodology, fixtures, and parametrization for comprehensive Python test coverage.
AI-generated summary based on this skill's SKILL.md
Install
affaan-m/ECC/python-testing · repository language: JavaScript
git clone https://github.com/affaan-m/ECC
cp -r ECC/skills/python-testing ~/.claude/skills/python-testingnpx skillfed install affaan-m/ECC/python-testingFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is python-testing and how does it help me write better tests?
python-testing teaches pytest essentials and test-driven development patterns for Python projects. The skill covers fixtures, parametrization, mocking, and coverage strategies to build reliable test suites. You'll learn to follow the red-green-refactor cycle and achieve 80%+ code coverage on your critical paths, ensuring your code is thoroughly validated before deployment.
How do I write python unit testing with pytest?
python-testing guides you through pytest fundamentals and test structure for Python projects. You'll learn how to organize tests, write assertions, use fixtures for setup and teardown, and apply parametrization to test multiple scenarios efficiently. The skill emphasizes learning pytest's core features and best practices for structuring test files and test functions to maximize clarity and maintainability.
What is the red-green-refactor cycle in test-driven development?
python-testing covers the test-driven development (TDD) workflow with red-green-refactor as a core pattern. Red means writing a failing test first; green means writing minimal code to pass it; refactor means improving the code while keeping tests passing. This cycle ensures your implementation is always validated and helps you design better APIs and catch bugs early.
How do I set up pytest fixtures and mocking for comprehensive coverage?
python-testing teaches you to set up fixtures, mocking, and parametrization for comprehensive test coverage. Fixtures provide reusable setup and teardown logic; mocking lets you safely test code that depends on external services or databases without actually calling them. You'll learn conftest patterns for sharing fixtures across tests and techniques for mocking API calls and database operations.
Can python-testing help me achieve 80%+ code coverage?
Yes. python-testing includes strategies for achieving 80%+ code coverage and testing critical paths thoroughly. The skill teaches you how to identify which code paths matter most, use coverage tools to measure your progress, and apply parametrization and fixtures to test edge cases and error conditions systematically.
How do I test async code and exceptions with pytest?
python-testing covers testing async code, exceptions, and external dependencies safely. You'll learn pytest plugins and patterns for async testing, how to assert that specific exceptions are raised, and techniques for mocking external dependencies so your tests remain fast and isolated. This ensures your async workflows and error handling are robust.
SKILL.md
rendered from the published skill — quoted content, verbatim
Python Testing Patterns
Comprehensive testing strategies for Python applications using pytest, TDD methodology, and best practices.
When to Activate
- Writing new Python code (follow TDD: red, green, refactor)
- Designing test suites for Python projects
- Reviewing Python test coverage
- Setting up testing infrastructure
Core Testing Philosophy
Test-Driven Development (TDD)
Always follow the TDD cycle:
- RED: Write a failing test for the desired behavior
- GREEN: Write minimal code to make the test pass
- REFACTOR: Improve code while keeping tests green
# Step 1: Write failing test (RED)
def test_add_numbers():
result = add(2, 3)
assert result == 5
# Step 2: Write minimal implementation (GREEN)
def add(a, b):
return a + b
# Step 3: Refactor if needed (REFACTOR)
Coverage Requirements
- Target: 80%+ code coverage
- Critical paths: 100% coverage required
- Use
pytest --covto measure coverage
```bash pytest
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
skills/python-testing/SKILL.md