Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问clear审计通过

python-testing-patternsPython 测试模式

Agent Skill

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。它适合让 Agent 阅读 Python 代码、定位测试问题、整理运行命令、生成脚本或分析数据处理逻辑。使用时需要确认项目虚拟环境、依赖版本和测试入口;涉及执行脚本、读写文件、访问数据库或调用外部 API 时,应先明确运行目录和输入输出范围,避免误改生产数据。

总安装

1,048

周安装

42

GitHub Stars

15

下载量

339
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:python-testing-patterns(Python 测试模式)
来源仓库:https://github.com/nickcrew/claude-ctx-plugin
仓库路径:skills/python-testing-patterns
安装命令:
npx skills add https://github.com/nickcrew/claude-ctx-plugin --skill python-testing-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/nickcrew/claude-ctx-plugin --skill python-testing-patterns

简介

python-testing-patterns 用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流,适合在 Python 开发和测试场景中使用。

  • 适用于 Python 开发者、测试工程师和 QA 人员进行测试用例编写和问题诊断。
  • 支持代码分析、测试计划生成和失败日志解读功能。
  • 安装命令为 npx skills add https://github.com/nickcrew/claude-ctx-plugin --skill python-testing-patterns。
  • 使用时需确认项目虚拟环境、依赖版本和测试入口;涉及外部 API 调用时应区分测试环境和生产环境。

SKILL.md

Python Testing Patterns

Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and property-based testing.

When to Use This Skill

  • Writing unit tests for Python functions and classes
  • Setting up comprehensive test suites and infrastructure
  • Implementing test-driven development (TDD) workflows
  • Creating integration tests for APIs, databases, and services
  • Mocking external dependencies and third-party services
  • Testing async code and concurrent operations
  • Implementing property-based testing with Hypothesis
  • Setting up CI/CD test automation
  • Debugging failing tests and improving test coverage

Core Concepts

Test Discovery: Files matching test_*.py or *_test.py, functions starting with test_

Fixtures: Reusable test resources with setup and teardown

  • Scopes: function (default), class, module, session
  • Composition: Build complex fixtures from simple ones
  • Share via conftest.py for project-wide availability

Assertions: Use assert statements, pytest.raises() for exceptions

Organization: Separate unit/, integration/, e2e/ directories

Quick Reference

Load detailed references for specific topics:

TaskReference File
Pytest basics, test structure, AAA patternskills/python-testing-patterns/references/pytest-fundamentals.md
Fixtures, scopes, setup/teardown, conftest.pyskills/python-testing-patterns/references/fixtures.md
Parametrization, multiple test casesskills/python-testing-patterns/references/parametrized-tests.md
Mocking, patching, unittest.mock, pytest-mockskills/python-testing-patterns/references/mocking.md
Async tests, pytest-asyncio, event loopsskills/python-testing-patterns/references/async-testing.md
Property-based testing, Hypothesis, strategiesskills/python-testing-patterns/references/property-based-testing.md
Monkeypatch, environment variables, attributesskills/python-testing-patterns/references/monkeypatch.md
Test structure, markers, conftest.py patternsskills/python-testing-patterns/references/test-organization.md
Coverage measurement, reports, thresholdsskills/python-testing-patterns/references/coverage.md
Database, API, Redis, message queue testingskills/python-testing-patterns/references/integration-testing.md
Best practices, test quality, fixture designskills/python-testing-patterns/references/best-practices.md

Workflow

1. Basic Test Setup

# test_example.py
import pytest

def test_something():
    """Descriptive test name."""
    # Arrange
    expected = 5

    # Act
    result = 2 + 3

    # Assert
    assert result == expected

Run tests:

pytest                    # Run all tests
pytest -v                 # Verbose output
pytest tests/unit/        # Specific directory
pytest -k "test_user"     # Match pattern
pytest -m unit            # Run marked tests

2. Using Fixtures

@pytest.fixture
def sample_data():
    """Provide test data."""
    data = {"key": "value"}
    yield data
    # Cleanup if needed

def test_with_fixture(sample_data):
    assert sample_data["key"] == "value"

3. Parametrized Tests

@pytest.mark.parametrize("input,expected", [
    (2, 4),
    (3, 9),
    (4, 16),
])
def test_square(input, expected):
    assert input ** 2 == expected

4. Mocking External Dependencies

from unittest.mock import patch

@patch("module.external_api_call")
def test_with_mock(mock_api):
    mock_api.return_value = {"status": "ok"}

    result = my_function()

    assert result["status"] == "ok"
    mock_api.assert_called_once()

5. Coverage Measurement

pytest --cov=src --cov-report=term-missing
pytest --cov=src --cov-report=html
pytest --cov=src --cov-fail-under=80

6. Test Configuration

pytest.ini:

[pytest]
testpaths = tests
python_files = test_*.py
addopts = -v --strict-markers --cov=src
markers =
    unit: Unit tests
    integration: Integration tests
    slow: Slow tests

Common Patterns

Exception testing:

with pytest.raises(ValueError, match="error message"):
    function_that_raises()

Async testing:

@pytest.mark.asyncio
async def test_async_function():
    result = await async_operation()
    assert result is not None

Temporary files:

def test_file_operation(tmp_path):
    test_file = tmp_path / "test.txt"
    test_file.write_text("content")
    assert test_file.read_text() == "content"

Markers for test selection:

@pytest.mark.slow
@pytest.mark.integration
def test_database_operation():
    pass

Common Mistakes

  1. Not using fixtures: Repeating setup code across tests

- Solution: Create fixtures in conftest.py

  1. Tests depending on order: Global state pollution

- Solution: Ensure test independence with proper fixtures

  1. Over-mocking: Mocking internal implementation

- Solution: Mock only external boundaries (APIs, databases)

  1. Missing edge cases: Only testing happy path

- Solution: Test boundary conditions, errors, and invalid inputs

  1. Slow tests: Running full integration tests frequently

- Solution: Separate unit/integration, use markers, optimize fixtures

  1. Ignoring coverage gaps: Not measuring test coverage

- Solution: Use pytest-cov and track metrics

  1. Poor test names: Generic names like test_1()

- Solution: Use descriptive names: test_<behavior>_<condition>_<expected>

  1. No cleanup: Resources not released

- Solution: Use fixtures with proper teardown (yield pattern)

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

29.86%
按下载量换算101

windsurf

23.84%
按下载量换算81

Antigravity

20.66%
按下载量换算70

Gemini CLI

12.85%
按下载量换算44

kilo

7.69%
按下载量换算26

trae

3.23%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills