# Python Test Strategy

> Python unit testing patterns for pytest, including test file structure, fixtures, mocks, and coverage strategy. Use when asked to write tests (unit/integration) for any Python module, function, class, or method. Use when this capability is needed.

- Skill: `tomevault-io/python-test-strategy` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/python-test-strategy`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/python-test-strategy/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/python-test-strategy

---


# 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:

```bash
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>.py` → `tests/<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

- 🎯 [Naming & File Location](./reference/naming.md)
- 📊 [Coverage Setup](./reference/coverage.md)
- 🔌 [Public API Testing](./reference/public-api.md)

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/machu-gwu) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-15 -->

