python-testing
Learn to build robust Python tests using pytest with test-driven development principles. This skill covers fixtures for setup and teardown, parametrization for running tests across multiple inputs, mocking to isolate dependencies, and achieving meaningful code coverage targets.
Python Testing teaches pytest-based testing strategies including TDD, fixtures, mocking, and parametrization.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-03-05
Python Testing teaches pytest-based testing strategies including TDD, fixtures, mocking, and parametrization. Learn to build robust Python tests using pytest with test-driven development principles. This skill covers fixtures for setup and teardown, parametrization for running tests across multiple inputs, mocking to isolate dependencies, and achieving meaningful code coverage targets.
Use it when
- python-testing explains fixture scopes and lifecycle management in pytest.
- Yes.
Verify before relying
Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.
Install
xu-xiang/everything-claude-code-zh/python-testing · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is the pytest testing framework and how does python-testing teach it?
python-testing covers pytest, the leading Python testing framework. The skill teaches you to write comprehensive tests using pytest's powerful features including assertions, fixtures for setup/teardown, parametrization for testing multiple inputs, and mocking to isolate dependencies. You'll learn test-driven development workflows where you write tests before implementation, ensuring robust code from the start.
How do pytest fixtures setup and teardown work in python-testing?
python-testing explains fixture scopes and lifecycle management in pytest. Fixtures provide reusable setup and teardown logic for your tests. The skill covers conftest.py for sharing fixtures across test files, different scope levels (function, class, module, session), and how to structure fixtures for maintainability. This eliminates code duplication and keeps tests clean and focused.
Can python-testing help me write parametrized tests across multiple test cases?
Yes. python-testing teaches parametrization patterns that let you run the same test logic with different inputs efficiently. Instead of writing duplicate test functions, you use pytest's parametrize decorator to specify multiple input sets. This reduces code duplication, improves maintainability, and makes it easy to test edge cases and various scenarios systematically.
How does python-testing cover mocking and patching in Python?
python-testing teaches mocking and patching techniques to isolate units under test from external dependencies. You'll learn to mock objects, patch functions, and control their behavior during tests. This allows you to test components independently without relying on databases, APIs, or other external systems, making tests faster and more reliable.
How can python-testing help me measure and improve code coverage?
python-testing covers code coverage measurement using pytest-cov to track which lines your tests execute. The skill guides you toward meaningful coverage targets of 80%+ and teaches best practices for improving coverage. You'll learn to identify untested code paths, write tests for edge cases, and structure test suites to maximize coverage while maintaining test quality and relevance.
What test-driven development workflow does python-testing implement?
python-testing teaches TDD principles where you write tests before implementation. This workflow improves design, catches bugs early, and ensures requirements are met. The skill covers organizing and structuring test suites for maintainability, using pytest markers for test selection, and integrating testing into your Python project workflow from the start.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Python 测试模式(Python Testing Patterns)
使用 pytest、测试驱动开发(TDD)方法论和最佳实践的 Python 应用程序综合测试策略。
何时激活
- 编写新的 Python 代码时(遵循 TDD:红、绿、重构)
- 为 Python 项目设计测试套件时
- 审查 Python 测试覆盖率时
- 搭建测试基础设施时
核心测试哲学
测试驱动开发 (TDD)
始终遵循 TDD 循环:
- 红(RED):为期望的行为编写一个失败的测试
- 绿(GREEN):编写最少的代码使测试通过
- 重构(REFACTOR):在保持测试通过的同时改进代码
# 步骤 1:编写失败的测试 (红)
def test_add_numbers():
result = add(2, 3)
assert result == 5
# 步骤 2:编写最简实现 (绿)
def add(a, b):
return a + b
# 步骤 3:如果需要则进行重构 (重构)
覆盖率要求
- 目标:80% 以上的代码覆盖率
- 关键路径:要求 100% 覆盖率
- 使用
pytest --cov来衡量覆盖率
pytest --cov=mypackage --cov-report=term-missing --cov-report=html
pytest 基础
基本测试结构
import pytest
def test_addition():
"""测试基本的加法。"""
assert 2 + 2 == 4
def test_string_uppercase():
"""测试字符串转大写。"""
text = "hello"
assert text.upper() == "HELLO"
def test_list_append():
"""测试列表追加。"""
items = [1, 2, 3]
items.append(4)
assert 4 in items
assert len(items) == 4
断言(Assertions)
```python
(truncated - see the full file via the links below)
File tree — 1 file
skills/python-testing/SKILL.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Learn pytest framework and write comprehensive Python tests”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
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.
pytest-skill equips you with patterns for writing robust Python tests using pytest's core features: fixtures for setup and teardown, parametrize for data-driven testing, markers for test organization, and mocking for external dependencies. It covers conftest configuration, exception handling, and best practices for production environments.
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.
pytest is Python's standard testing framework, enabling developers to write organized unit and integration tests through fixtures for dependency injection and parametrization for data-driven test cases. It supports async code, multiple test discovery patterns, and integrates seamlessly with FastAPI, Django, and Flask, plus a rich plugin ecosystem for coverage, mocking, and parallel execution.
This skill automates the creation of constructor validation tests for Python service classes. It analyzes service __init__ methods to generate pytest test cases that verify required parameters raise ValueError when None, following the fail-fast principle.
Master MCP by building secure servers and clients that connect AI assistants to external tools and resources. This skill covers tool registration, transport configuration, authorization patterns, and performance optimization through test-driven development and security-first principles.
More skills python-testing-patterns (MIT) · Pytest Patterns (unlicensed) · Pytest Testing (NOASSERTION) · Pytest Patterns (unlicensed) · python-testing (MIT) · python-testing-patterns (MIT) · Pytest (unlicensed) · django-tdd (MIT)