关于 pytest-config
用于在 Claude Night Market 插件中统一 pytest 配置和可复用测试基础设施的技能,面向需要共享夹具、标记、覆盖率设置及 CI 模式的 Python 项目。
主要功能
- 01pytest 配置模式
- 02可复用的 conftest 夹具
- 03测试标记与目录结构
- 04覆盖率和 CI 指引
适用场景
- 01为 Python 项目配置 pytest
- 02创建共享测试夹具
- 03统一插件测试基础设施
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ athola/ claude-night-market --skill pytest-config安装后在 Claude Code 中输入/pytest-config确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
modules/ci-integration.mdconftest-patterns.mdgit-testing-fixtures.mdmock-fixtures.mdREADME.md详细介绍
Pytest 配置模式
为 Claude Night Market 插件提供标准化的 pytest 配置和模式,确保测试基础设施一致。
适用场景
- 设置 pytest 配置和固件
- 配置用于测试基础设施的 conftest.py 模式
不适用场景
- 非 Python 项目或使用其他测试框架的项目
- 不需要测试基础设施的简单脚本
快速入门
基本的 pyproject.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
验证: 运行 pytest --collect-only 验证测试发现,运行 pytest -v --co -q 检查标记,并运行 pytest --cov 检查覆盖率阈值。
详细模式
如需了解详细的实现模式,请参阅:
- Conftest 模式 - Conftest.py 模板、固件、测试标记和目录结构
- Git 测试固件 - 用于测试 Git 工作流的 GitRepository 辅助类
- 模拟固件 - 用于 Bash、TodoWrite 和其他 Claude Code 工具的模拟工具固件
- CI 集成 - 用于自动化测试的 GitHub Actions 工作流和测试命令
- 模块索引:查看
modules/README.md,了解模块组织概览
与其他技能集成
此技能提供基础模式,供以下技能引用:
parseltongue:python-testing- 使用 pytest 配置和固件pensive:test-review- 使用测试质量标准sanctum:test-*- 使用 conftest 模式和 Git 固件
在技能的 frontmatter 中引用:
dependencies: [leyline:pytest-config, leyline:testing-quality-standards]
完成标准
- 在各插件间统一 pytest 配置
- conftest.py 提供可复用的固件
- 定义并记录测试标记
- 覆盖率配置强制执行质量阈值
- 配置 CI/CD 集成以进行自动化测试
故障排除
常见问题
未发现测试
确保测试文件符合 test_*.py 或 *_test.py 模式。运行 pytest --collect-only 进行验证。
导入错误
检查被测模块是否位于 PYTHONPATH 中,或使用 pip install -e . 安装
异步测试失败
安装 pytest-asyncio,并使用 @pytest.mark.asyncio 装饰测试函数
评论
支持 Markdown