uv-pytest-unit-testing
4
总安装量
3
周安装量
#52808
全站排名
安装命令
npx skills add https://github.com/gaelic-ghost/python-skills --skill uv-pytest-unit-testing
Agent 安装分布
codex
3
cline
2
github-copilot
2
kimi-cli
2
gemini-cli
2
cursor
2
Skill 文档
Uv Pytest Unit Testing
Overview
Use this skill to standardize pytest setup and execution for uv-managed Python repositories, including single-project repos and uv workspaces.
Workflow
- Detect repository mode.
- Treat repo as workspace when
pyproject.tomldefines[tool.uv.workspace]. - Treat repo as single project otherwise.
- Bootstrap pytest dependencies and baseline config.
- Run
scripts/bootstrap_pytest_uv.sh --workspace-root <repo>. - Add
--package <member-name>for workspace member package setup. - Add
--with-covwhenpytest-covshould be installed and baseline coverage flags added. - Add
--dry-runto preview all actions without mutating files.
- Run tests with uv.
- Run
scripts/run_pytest_uv.sh --workspace-root <repo>for root-project execution. - Run
scripts/run_pytest_uv.sh --workspace-root <repo> --package <member-name>for workspace member execution. - Pass through pytest selectors/options after
--, for example:scripts/run_pytest_uv.sh --workspace-root <repo> -- --maxfail=1 -qscripts/run_pytest_uv.sh --workspace-root <repo> --package api --path tests/unit -- -k auth -m "not slow"
- Apply balanced quality gates.
- Require passing test runs before concluding work.
- Recommend coverage reporting as guidance, not a hard threshold, unless user explicitly requests enforced minimum coverage.
- Troubleshoot failures in this order.
- Confirm command context: root vs
--packagerun target. - Confirm test discovery layout:
tests/,test_*.py,*_test.py. - Confirm marker registration in
tool.pytest.ini_options.markerswhen custom markers are used. - Confirm import path assumptions (package install mode, working directory, and module names).
Test Authoring Guidance
- Keep fast unit tests under
tests/unitand integration-heavy tests undertests/integrationwhen repo size warrants separation. - Use fixtures for setup reuse, and keep fixture scope minimal (
functionby default). - Use
@pytest.mark.parametrizefor matrix-style cases instead of hand-written loops. - Use
monkeypatchfor environment variables and runtime dependency replacement. - Register custom marks in config to avoid marker warnings.
References
- Use
references/pytest-workflow.mdfor pytest conventions, config keys, fixtures, markers, and troubleshooting. - Use
references/uv-workspace-testing.mdfor uv workspace execution patterns (uv run,uv run --package, package-targeted test runs).
Resources
scripts/
scripts/bootstrap_pytest_uv.sh: Install pytest dev dependencies and append baselinetool.pytest.ini_optionswhen missing.scripts/run_pytest_uv.sh: Run pytest via uv for root project or workspace member package, with passthrough args.
references/
references/pytest-workflow.md: Practical pytest setup and usage guidance.references/uv-workspace-testing.md: uv execution guidance for single-project and workspace repositories.