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.toml defines [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-cov when pytest-cov should be installed and baseline coverage flags added.
- Add
--dry-run to 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 -q
scripts/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
--package run target.
- Confirm test discovery layout:
tests/, test_*.py, *_test.py.
- Confirm marker registration in
tool.pytest.ini_options.markers when 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/unit and integration-heavy tests under tests/integration when repo size warrants separation.
- Use fixtures for setup reuse, and keep fixture scope minimal (
function by default).
- Use
@pytest.mark.parametrize for matrix-style cases instead of hand-written loops.
- Use
monkeypatch for environment variables and runtime dependency replacement.
- Register custom marks in config to avoid marker warnings.
Automation Suitability
- Codex App automation: High. Strong recurring fit for test health checks, failure triage, and drift detection.
- Codex CLI automation: High. Strong fit for non-interactive test setup and targeted test sweeps.
Codex App Automation Prompt Template
Use $uv-pytest-unit-testing.
Scope boundaries:
- Work only inside <REPO_PATH>.
- Operate only on pytest setup and test execution tasks.
- Do not perform unrelated code refactors.
Task:
1. Detect repository mode from <WORKSPACE_ROOT>/pyproject.toml.
2. If <DRY_RUN_BOOTSTRAP:TRUE|FALSE> is TRUE, run:
`scripts/bootstrap_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <WITH_COV_FLAG> --dry-run`
3. If <DRY_RUN_BOOTSTRAP:TRUE|FALSE> is FALSE, run:
`scripts/bootstrap_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <WITH_COV_FLAG>`
4. Run tests with:
`scripts/run_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <TEST_PATH_FLAG> -- <PYTEST_ARGS>`
5. Keep package-targeted runs explicit when <PACKAGE_NAME_OR_EMPTY> is set.
Output contract:
1. STATUS: PASS or FAIL
2. SETUP: what bootstrap actions ran
3. TEST_RESULTS: concise pass/fail summary
4. FAILURES: grouped likely causes
5. NEXT_STEPS: minimal remediation actions
Codex CLI Automation Prompt Template
codex exec --full-auto --sandbox workspace-write --cd "<REPO_PATH>" "<PROMPT_BODY>"
<PROMPT_BODY> template:
Use $uv-pytest-unit-testing.
Limit scope to pytest setup and execution in <WORKSPACE_ROOT>.
Run bootstrap in dry-run or real mode based on <DRY_RUN_BOOTSTRAP:TRUE|FALSE>.
Run tests with explicit package targeting when <PACKAGE_NAME_OR_EMPTY> is set.
Return STATUS, setup actions, concise test summary, grouped likely causes for failures, and minimal next steps.
Customization Placeholders
<REPO_PATH>
<WORKSPACE_ROOT>
<PACKAGE_NAME_OR_EMPTY>
<PACKAGE_FLAG>
<TEST_PATH_OR_EMPTY>
<TEST_PATH_FLAG>
<PYTEST_ARGS>
<WITH_COV_FLAG:--with-cov|EMPTY>
<DRY_RUN_BOOTSTRAP:TRUE|FALSE>
Interactive Customization Workflow
- Ask whether users want bootstrap mode or run mode.
- Gather workspace root and optional package target.
- For bootstrap mode, gather
with_cov and dry_run.
- For run mode, gather optional test path and optional pytest args.
- Return both:
- A YAML profile for durable reuse.
- The exact command to run.
- Use this precedence order:
- CLI flags
--config profile file
.codex/profiles/uv-pytest-unit-testing/customization.yaml
~/.config/gaelic-ghost/python-skills/uv-pytest-unit-testing/customization.yaml
- Script defaults
- If users want temporary reset behavior:
--bypassing-all-profiles
--bypassing-repo-profile
--deleting-repo-profile
- If users provide no customization or profile files, keep existing script defaults unchanged.
- See
references/interactive-customization.md for schema and examples.
References
- Use
references/pytest-workflow.md for pytest conventions, config keys, fixtures, markers, and troubleshooting.
- Use
references/uv-workspace-testing.md for 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 baseline tool.pytest.ini_options when 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.
Source: prabhulkarraj05/python-skills — distributed by TomeVault.
1---2name: uv-pytest-unit-testing3description: Set up and run unit tests for Python uv projects and uv workspaces with pytest. Use when creating or updating pytest configuration in pyproject.toml, installing pytest dev dependencies with uv, running tests in a workspace member package via `uv run --package`, customizing pytest workflow defaults through layered YAML profiles, organizing tests with fixtures/markers/parametrize, or troubleshooting test discovery and import failures. Use when this capability is needed.4---56# Uv Pytest Unit Testing78## Overview910Use this skill to standardize pytest setup and execution for uv-managed Python repositories, including single-project repos and uv workspaces.1112## Workflow13141. Detect repository mode.15- Treat repo as workspace when `pyproject.toml` defines `[tool.uv.workspace]`.16- Treat repo as single project otherwise.17182. Bootstrap pytest dependencies and baseline config.19- Run `scripts/bootstrap_pytest_uv.sh --workspace-root <repo>`.20- Add `--package <member-name>` for workspace member package setup.21- Add `--with-cov` when `pytest-cov` should be installed and baseline coverage flags added.22- Add `--dry-run` to preview all actions without mutating files.23243. Run tests with uv.25- Run `scripts/run_pytest_uv.sh --workspace-root <repo>` for root-project execution.26- Run `scripts/run_pytest_uv.sh --workspace-root <repo> --package <member-name>` for workspace member execution.27- Pass through pytest selectors/options after `--`, for example:28 - `scripts/run_pytest_uv.sh --workspace-root <repo> -- --maxfail=1 -q`29 - `scripts/run_pytest_uv.sh --workspace-root <repo> --package api --path tests/unit -- -k auth -m "not slow"`30314. Apply balanced quality gates.32- Require passing test runs before concluding work.33- Recommend coverage reporting as guidance, not a hard threshold, unless user explicitly requests enforced minimum coverage.34355. Troubleshoot failures in this order.36- Confirm command context: root vs `--package` run target.37- Confirm test discovery layout: `tests/`, `test_*.py`, `*_test.py`.38- Confirm marker registration in `tool.pytest.ini_options.markers` when custom markers are used.39- Confirm import path assumptions (package install mode, working directory, and module names).4041## Test Authoring Guidance4243- Keep fast unit tests under `tests/unit` and integration-heavy tests under `tests/integration` when repo size warrants separation.44- Use fixtures for setup reuse, and keep fixture scope minimal (`function` by default).45- Use `@pytest.mark.parametrize` for matrix-style cases instead of hand-written loops.46- Use `monkeypatch` for environment variables and runtime dependency replacement.47- Register custom marks in config to avoid marker warnings.4849## Automation Suitability5051- Codex App automation: High. Strong recurring fit for test health checks, failure triage, and drift detection.52- Codex CLI automation: High. Strong fit for non-interactive test setup and targeted test sweeps.5354## Codex App Automation Prompt Template5556```markdown57Use $uv-pytest-unit-testing.5859Scope boundaries:60- Work only inside <REPO_PATH>.61- Operate only on pytest setup and test execution tasks.62- Do not perform unrelated code refactors.6364Task:651. Detect repository mode from <WORKSPACE_ROOT>/pyproject.toml.662. If <DRY_RUN_BOOTSTRAP:TRUE|FALSE> is TRUE, run:67 `scripts/bootstrap_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <WITH_COV_FLAG> --dry-run`683. If <DRY_RUN_BOOTSTRAP:TRUE|FALSE> is FALSE, run:69 `scripts/bootstrap_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <WITH_COV_FLAG>`704. Run tests with:71 `scripts/run_pytest_uv.sh --workspace-root <WORKSPACE_ROOT> <PACKAGE_FLAG> <TEST_PATH_FLAG> -- <PYTEST_ARGS>`725. Keep package-targeted runs explicit when <PACKAGE_NAME_OR_EMPTY> is set.7374Output contract:751. STATUS: PASS or FAIL762. SETUP: what bootstrap actions ran773. TEST_RESULTS: concise pass/fail summary784. FAILURES: grouped likely causes795. NEXT_STEPS: minimal remediation actions80```8182## Codex CLI Automation Prompt Template8384```bash85codex exec --full-auto --sandbox workspace-write --cd "<REPO_PATH>" "<PROMPT_BODY>"86```8788`<PROMPT_BODY>` template:8990```markdown91Use $uv-pytest-unit-testing.92Limit scope to pytest setup and execution in <WORKSPACE_ROOT>.93Run bootstrap in dry-run or real mode based on <DRY_RUN_BOOTSTRAP:TRUE|FALSE>.94Run tests with explicit package targeting when <PACKAGE_NAME_OR_EMPTY> is set.95Return STATUS, setup actions, concise test summary, grouped likely causes for failures, and minimal next steps.96```9798## Customization Placeholders99100- `<REPO_PATH>`101- `<WORKSPACE_ROOT>`102- `<PACKAGE_NAME_OR_EMPTY>`103- `<PACKAGE_FLAG>`104- `<TEST_PATH_OR_EMPTY>`105- `<TEST_PATH_FLAG>`106- `<PYTEST_ARGS>`107- `<WITH_COV_FLAG:--with-cov|EMPTY>`108- `<DRY_RUN_BOOTSTRAP:TRUE|FALSE>`109110## Interactive Customization Workflow1111121. Ask whether users want bootstrap mode or run mode.1132. Gather workspace root and optional package target.1143. For bootstrap mode, gather `with_cov` and `dry_run`.1154. For run mode, gather optional test path and optional pytest args.1165. Return both:117- A YAML profile for durable reuse.118- The exact command to run.1196. Use this precedence order:120- CLI flags121- `--config` profile file122- `.codex/profiles/uv-pytest-unit-testing/customization.yaml`123- `~/.config/gaelic-ghost/python-skills/uv-pytest-unit-testing/customization.yaml`124- Script defaults1257. If users want temporary reset behavior:126- `--bypassing-all-profiles`127- `--bypassing-repo-profile`128- `--deleting-repo-profile`1298. If users provide no customization or profile files, keep existing script defaults unchanged.1309. See [`references/interactive-customization.md`](references/interactive-customization.md) for schema and examples.131132## References133134- Use [`references/pytest-workflow.md`](references/pytest-workflow.md) for pytest conventions, config keys, fixtures, markers, and troubleshooting.135- Use [`references/uv-workspace-testing.md`](references/uv-workspace-testing.md) for uv workspace execution patterns (`uv run`, `uv run --package`, package-targeted test runs).136137## Resources138139### scripts/140141- `scripts/bootstrap_pytest_uv.sh`: Install pytest dev dependencies and append baseline `tool.pytest.ini_options` when missing.142- `scripts/run_pytest_uv.sh`: Run pytest via uv for root project or workspace member package, with passthrough args.143144### references/145146- `references/pytest-workflow.md`: Practical pytest setup and usage guidance.147- `references/uv-workspace-testing.md`: uv execution guidance for single-project and workspace repositories.148149---150> Source: [prabhulkarraj05/python-skills](https://github.com/prabhulkarraj05/python-skills) — distributed by [TomeVault](https://tomevault.io).151<!-- tomevault:4.0:skill_md:2026-06-16 -->