Debian Codegraph @

context/running-tests.md

raw
1 # Running tests
2
3 All testing uses `ansible-test`, which supports sanity tests (linting/static analysis), unit tests, and integration tests.
4
5 ## Sanity tests
6
7 Sanity tests don't require `--docker`.
8 Some tests may be skipped if their dependencies aren't installed locally (e.g. additional Python versions, shellcheck, PowerShell),
9 but this rarely matters when testing your own changes.
10
11 Run sanity tests against all files in your change set, not just the ones you're actively editing.
12
13 ```bash
14 # Run all sanity tests
15 ansible-test sanity -v
16
17 # List available sanity tests
18 ansible-test sanity --list-tests
19
20 # Run specific sanity tests
21 ansible-test sanity -v --test pep8 --test pylint
22
23 # Run sanity on specific files (paths relative to repo root)
24 ansible-test sanity -v lib/ansible/modules/command.py
25
26 # Run all sanity tests in a container (for full coverage)
27 ansible-test sanity -v --docker
28 ```
29
30 > [!NOTE]
31 > `--docker` without an argument defaults to the `default` container.
32 > Avoid placing a non-container argument immediately after `--docker`, as it will be interpreted as an image name.
33
34 ## Unit tests
35
36 ```bash
37 # Run all unit tests
38 ansible-test units -v --docker
39
40 # Run a specific unit test (paths relative to repo root, targets in test/units/)
41 ansible-test units -v --docker test/units/modules/test_command.py
42
43 # Run with coverage
44 ansible-test units -v --docker --coverage
45 ```
46
47 ## Integration tests
48
49 ```bash
50 # Run all integration tests
51 ansible-test integration -v --docker ubuntu
52
53 # Run a specific integration target (directory name in test/integration/targets/)
54 ansible-test integration -v --docker ubuntu ping
55 ```
56
57 ## Container selection
58
59 - Sanity/Unit tests: `--docker` (defaults to the `default` container).
60 - Integration tests: `--docker ubuntu`, `--docker fedora`, etc. (NOT default/base).
61
62 The `base` and `default` containers are for sanity/unit tests only.
63 For integration tests, use distro-specific containers, depending on the modules being tested.
64
65 Available containers and their supported Python versions are listed in the `--help` output for each test command.
66
67 ## Test isolation options
68
69 - `--docker` (supports Docker or Podman) -- preferred for reliable, isolated testing.
70 - `--venv` -- fallback when containers are unavailable, but unit tests may be unreliable due to host environment differences.