mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 19:56:53 +00:00
Reorders all documented and scripted `make` invocations from the `VAR=value make target` shell-env prefix form to the make-native `make target VAR=value` form. GNU Make auto-exports both command-line and inherited shell-env variables to recipe shells, so the change is purely about command-line shape: only the make-suffix form starts with `make` and is therefore matched by the `Bash(make*)` permission entry in .claude/settings.json, avoiding unnecessary approval prompts for agent runs. Adds an explicit CLAUDE.md rule with ✅/❌ examples and the underlying reason (permission prefix match, not Makefile semantics). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1.7 KiB
1.7 KiB
Unit Tests 🧪
This page is the SPOT for unit testing requirements, framework, and structure.
Run unit tests with make test-unit.
Framework 🧰
- You MUST use Python
unittestas the test framework. - Tests MUST live under
tests/unit/. - Mirror the source tree: a file at
plugins/lookup/service.pygets its tests attests/unit/plugins/lookup/test_service.py.
Requirements 📋
- You MUST add or update unit tests for every
*.pyfile 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
.ymlor.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.mockto isolate the unit under test from Ansible internals or external state.
How to Create 🛠️
- Identify the module under test (e.g.
plugins/lookup/service.py). - Create the matching test file under
tests/unit/if it does not exist. - Subclass
unittest.TestCase. - Write one method per behavior. Build hypotheses before writing assertions.
- Run
make test-unitand 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