# Python Unit Tests

Use when writing, fixing, or reviewing Python pytest unit tests, fixtures, mocks, or...

- Repository: https://github.com/dimensionalOS/dimos (4702 stars)
- Category: Testing
- License: see repository
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add dimensionalOS/dimos --skill python-unit-tests -g -a claude-code -y`
Codex: `npx skills add dimensionalOS/dimos --skill python-unit-tests -g -a codex -y`
Cursor: `npx skills add dimensionalOS/dimos --skill python-unit-tests -g -a cursor -y`
Gemini CLI: `npx skills add dimensionalOS/dimos --skill python-unit-tests -g -a gemini-cli -y`

## Description

Use when writing, fixing, or reviewing Python pytest unit tests, fixtures, mocks, or test PR feedback.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Python Unit Tests

Use this skill before adding, changing, or reviewing Python unit tests. The goal is **hermetic** tests: behavior-focused, deterministic, isolated, and cheap to run.

Consult these only when the branch needs more context:

- `docs/coding-agents/testing.md`
- `docs/coding-agents/code-quality-rules.md`
- `docs/development/testing.md`
- `misc/auto-fixes/fix_template.md`

## Steps

1. **Scope the behavior.** Identify the code under test, the caller-visible outcome, and the smallest test file next to it: `dimos/core/foo.py` gets `dimos/core/test_foo.py`. Completion: every new or changed test has a named behavior target and lives beside the code it covers.
2. **Build a hermetic setup.** Use module-level imports, Arrange-Act-Assert structure, fixtures for shared or resource-owning setup, and context managers for one-test local resources. Completion: setup owns all cleanup, restores global state, reuses existing fixtures when they match, and contains no fixed sleeps.
3. **Assert the contract.** Use small examples and exact expected values. Completion: every test has an unconditional assertion that proves behavior a caller depends on.
4. **Mock the boundary.** Mock only slow, nondeterministic, or external boundaries. Completion: patches use `mocker.patch`, `mocker.patch.object`, or `monkeypatch`; no direct method assignment or `__new__` fixture shells remain.
5. **Validate tightly.** Run the smallest command that can fail for the change, then broaden only when the edit justifies it. Completion: the relevant pytest command has run, and mypy/pre-commit have run only when production source typing or broad quality gates changed.

## Test shape

The rest: https://github.com/dimensionalOS/dimos/blob/HEAD/.agents/skills/python-unit-tests/SKILL.md
