AgentSkillsCN

pytest-config

分析并提升现有代码的质量:消除重复代码、优化算法效率、践行整洁代码原则、确保架构契合度、规避“烂代码”模式,以及强化错误处理的稳健性。当您需要提升代码质量、减少 AI 产生的“烂代码”、为代码清晰度进行重构、优化算法、应用整洁代码原则时,可优先选用此技能。切勿在清除废弃/未使用的代码时使用——请改用 conserve:bloat-detector。在排查 bug 时——请改用 pensive:bug-review。在选择架构范式时——请改用 archetypes skills。此技能积极提升现有代码质量,通过质量优化(提升现有代码)与漏洞检测(清除废弃代码)相辅相成,共同推动代码质量的持续改善。

SKILL.md
--- frontmatter
name: pytest-config
description: |
  Standardized pytest configuration for plugin development with shared test patterns.

  pytest configuration, conftest, fixtures, test setup
  Use when: setting up pytest for plugin development or creating fixtures
category: infrastructure
tags: [pytest, testing, configuration, fixtures]
dependencies: [leyline:testing-quality-standards]
estimated_tokens: 200
provides:
  infrastructure: [pytest-config, conftest-patterns, coverage-config]
modules:
  - modules/conftest-patterns.md
  - modules/git-testing-fixtures.md
  - modules/mock-fixtures.md
  - modules/ci-integration.md
version: 1.4.0

Table of Contents

Pytest Configuration Patterns

Standardized pytest configuration and patterns for consistent testing infrastructure across Claude Night Market plugins.

When To Use

  • Setting up pytest configuration and fixtures
  • Configuring conftest.py patterns for test infrastructure

When NOT To Use

  • Non-Python projects or projects using other test frameworks
  • Simple scripts that do not need test infrastructure

Quick Start

Basic pyproject.toml Configuration

toml
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
    "-v",
    "--cov=src",
    "--cov-report=term-missing",
    "--cov-fail-under=80",
    "--strict-markers",
]
markers = [
    "unit: marks tests as unit tests",
    "integration: marks tests as integration tests",
    "slow: marks tests as slow running",
]

[tool.coverage.run]
source = ["src"]
omit = ["*/tests/*", "*/migrations/*", "*/__pycache__/*"]
branch = true

[tool.coverage.report]
exclude_lines = [
    "pragma: no cover",
    "def __repr__",
    "def __str__",
    "raise NotImplementedError",
    "if __name__ == .__main__.:",
    "if TYPE_CHECKING:",
    "class .*\\bProtocol\\):",
    "@(abc\\.)?abstractmethod",
]
precision = 2
show_missing = true

Verification: Run pytest -v to verify tests pass.

Detailed Patterns

For detailed implementation patterns, see:

  • Conftest Patterns - Conftest.py templates, fixtures, test markers, and directory structure
  • Git Testing Fixtures - GitRepository helper class for testing git workflows
  • Mock Fixtures - Mock tool fixtures for Bash, TodoWrite, and other Claude Code tools
  • CI Integration - GitHub Actions workflows and test commands for automated testing
  • Module Index: See modules/README.md for module organization overview

Integration with Other Skills

This skill provides foundational patterns referenced by:

  • parseltongue:python-testing - Uses pytest configuration and fixtures
  • pensive:test-review - Uses test quality standards
  • sanctum:test-* - Uses conftest patterns and Git fixtures

Reference in your skill's frontmatter:

yaml
dependencies: [leyline:pytest-config, leyline:testing-quality-standards]

Verification: Run pytest -v to verify tests pass.

Exit Criteria

  • pytest configuration standardized across plugins
  • conftest.py provides reusable fixtures
  • test markers defined and documented
  • coverage configuration enforces quality thresholds
  • CI/CD integration configured for automated testing

Troubleshooting

Common Issues

Tests not discovered Ensure test files match pattern test_*.py or *_test.py. Run pytest --collect-only to verify.

Import errors Check that the module being tested is in PYTHONPATH or install with pip install -e .

Async tests failing Install pytest-asyncio and decorate test functions with @pytest.mark.asyncio