Files
computer-playbook/docs/contributing/actions/testing/unit.md
T
kevinveenbirkenbachandClaude Opus 4.7 7d7301614d docs(changelog): per-release archive CLI + release docs + SPOT cleanup
Add cli/contributing/changelog/archive: a CLI that trims CHANGELOG.md
to the last N entries (default 7) and writes every older release to
its own file under docs/changelog/ named <padded-semver>-<date>.md
(7.0.0 → 007.000.000-2026-05-08.md). The padded form makes a directory
listing already chronological, and the index in CHANGELOG.md is
rebuilt from the archive directory listing on every run, so it never
drifts away from what is on disk. The tool is idempotent and never
overwrites an existing archive file.

Run the migration once to split the 44-entry CHANGELOG.md into 7
inline entries plus 37 archived per-release files, with the index at
the bottom of CHANGELOG.md linking each archive in descending order.

Add docs/contributing/actions/release.md as the contributor-facing
release procedure (versioning, active window vs. archive, cutting a
release end-to-end, CI hand-off on tag push) and add a docs README
under docs/changelog/ that explains the archive directory layout and
filename schema. Cross-link release.md from pipeline.md and add
"releases" to the actions/ scope description.

Documentation cleanup pass on every page touched in the previous
mapping refactor:

- Remove "is the SPOT for X" / "Single Point of Truth" self-labels
  across docs/contributing/, docs/agents/, and docs/changelog/. The
  rule in documentation.md forbids self-declared SPOT status; status
  is conferred by readers cross-linking, not by the page asserting
  it. Rephrase to descriptive phrasing ("This page covers X",
  "describes X", "lists X") throughout.
- Drop the orphaned docs/contributing/tools/actions.md duplicate
  (101 lines paralleling tools/github/actions/workflows.md, with no
  inbound links).
- Fix em-dashes used as thought breaks in dockerfile.md, origin.md,
  agents/style.css.md, and suppression.md per documentation.md.
- Unwrap soft-wrapped sentences in iam/common.md, iam/ldap.md,
  iam/oidc.md, image/origin.md, requirements.md, and dockerfile.md
  so each logical line carries one full sentence.

Add a unit test for the archive CLI under
tests/unit/cli/contributing/changelog/archive/test_main.py covering
_pad_version, _split_into_entries, idempotency, dry-run, no-overwrite
of existing archives, and the multi-run index rebuild.

Quote `# noqa:` in CHANGELOG.md prose with backticks so the
noqa-only-ruff-codes lint does not parse "for" as a non-ruff code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 16:19:42 +02:00

1.7 KiB

Unit Tests 🧪

This page covers unit testing requirements, framework, and structure. Run unit tests with make test-unit.

Framework 🧰

  • You MUST use Python unittest as the test framework.
  • Tests MUST live under tests/unit/.
  • Mirror the source tree: a file at plugins/lookup/service.py gets its tests at tests/unit/plugins/lookup/test_service.py.

Requirements 📋

  • You MUST add or update unit tests for every *.py file you touch.
  • Each test MUST cover one isolated behavior. Do not test multiple concerns in a single test method.
  • You MUST NOT write tests that only assert a file contains a string.
  • You MUST NOT write tests for non-executable files such as .yml or .j2. Test the code that consumes them instead.
  • You SHOULD name test methods after the behavior they verify, not the function name alone (e.g. test_needed_false_when_disabled).
  • You SHOULD cover edge cases: empty inputs, missing keys, and boundary values, not only the happy path.
  • You MAY use unittest.mock to isolate the unit under test from Ansible internals or external state.

How to Create 🛠️

  1. Identify the module under test (e.g. plugins/lookup/service.py).
  2. Create the matching test file under tests/unit/ if it does not exist.
  3. Subclass unittest.TestCase.
  4. Write one method per behavior. Build hypotheses before writing assertions.
  5. Run make test-unit and verify all tests pass.

Running Specific Tests 🏃

Use TEST_PATTERN to scope the test run to a single file or a glob:

# Run a single test file
make test-unit TEST_PATTERN=test_my_module.py

# Run all files matching a prefix
make test-unit TEST_PATTERN=test_applications*.py