Skills

Python Unit Tests

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

Install

npx skills add dimensionalOS/dimos --skill python-unit-tests -g -a claude-code -y
Repository
dimensionalOS/dimos4.7k
Category
Testing
Updated
3d ago
License
See repository
Context cost
Lightabout 1,398 tokens
Runs scripts
No, instructions only

What it does

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

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

Read the whole SKILL.md on GitHub

More in Testing