返回 Skill 列表
extension
分类: 开发与工程无需 API Key

python-test-strategy

Python单元测试模式,适用于pytest,包括测试文件结构、fixtures、mocks和覆盖率策略。在被要求为任何Python模块、函数、类或方法编写测试(单元/集成)时使用。

person作者: jakexiaohubgithub

python-test-strategy

Organized testing strategy for Python projects: test file naming, coverage goals (95%+), and public API testing.

Quick Start

Find test location for any source file:

When being asked to write tests for a specific source file, use the following command to determine the correct test file path based on established naming conventions:

uvx --from shai-py==0.1.1 shai-py test-path /path/to/my_package/subpackage/module.py

Run tests:

  • Individual file: .venv/bin/python tests/subpackage/test_*.py
  • Package: .venv/bin/python tests/subpackage/all.py
  • All: .venv/bin/python tests/all.py

Key Patterns

  • Test files mirror source: source/<pkg>/<module>.pytests/<pkg>/test_<pkg>_<module>.py
  • Coverage goal: 95%+ for all implementation files
  • Public API: Export all public interfaces in api.py, test in tests/test_api.py

References