Skip to content

Commit a82efdc

Browse files
authored
Update test isolation logic (#546)
1 parent b1fb5c1 commit a82efdc

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

docs/user-guide/test-isolation.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,53 @@ an unpredictable way.
2828
Starting with early 2025, all ansible-dev-tools will aim to implement the
2929
following predictable behaviors:
3030

31-
- Prefer being run from within a python virtual environment, warning the user
32-
if this not the case.
31+
- Prefer being run from within a **writable** python virtual environment,
32+
warning the user if this not the case.
3333
- Dynamically modify Ansible environment to prefer installation of dependencies
3434
such as collections, roles and python packages inside the current virtual
3535
environment.
3636

37-
## Isolated mode (virtual environment) \[default\]
37+
## Isolated mode (default)
3838

39-
This is the recommended way to run ansible-dev-tools. If a virtual environment
40-
is not detected, a warning will be displayed, prompting the user to use one
41-
for better isolation.
39+
- First folder that is not read-only from the list below will be used as cache directory and also :
4240

43-
It should be noted that our tools will look for a `.venv` directory inside
44-
the current directory if a virtual environment is not already active and will
45-
try to use it if found.
41+
- `$VIRTUAL_ENV/.ansible` for anything but collections, those will be inside `lib/python3.*/site-packages/ansible_collections` because this makes them available to ansible-core without any additional configuration.
42+
- `$PROJECT_ROOT/.ansible`
43+
- `$TMPDIR/.ansible-<sha256>` for temporary installations
4644

47-
When running ansible-dev-tools inside a virtual environment, the following
48-
things will happen:
45+
- `ANSIBLE_HOME` will be defined to point to it, preventing accidental use of user's home directory. Its existing value will be ignored. If you want to avoid this, see non-isolated mode below.
46+
47+
### Virtual environment detection
48+
49+
Our tools will look for presence of `VIRTUAL_ENV` variable and use it.
50+
Otherwise they will also try to look a `.venv` directory inside
51+
the project directory will try to use it if found.
52+
53+
When running ansible-dev-tools inside a **writable** virtual environment,
54+
the following things will happen:
4955

5056
- Few Ansible environment variables will be automatically defined in order to
5157
make `ansible-galaxy` install commands to install content (collections and
52-
roles) directly inside the virtual environment. Ansible-core itself is already able to find content from inside the virtual environment and this takes priority over the other paths.
58+
roles) directly inside the virtual environment. Ansible-core itself is
59+
already able to find content from inside the virtual environment and this
60+
takes priority over the other paths.
5361
- Dependencies will automatically be installed inside the virtual environment
5462

55-
## Non-isolated mode (outside virtual environments)
63+
## Non-isolated mode
64+
65+
No changing of ansible include paths will be performed, and a warning will be
66+
displayed telling user that its user environment is not isolated and that
67+
result of tool execution may produce unpredictable results on other systems.
68+
69+
The cache directory will point to `$ANSIBLE_HOME/tmp/compat-ZZZ`, where ZZZ is
70+
a sha256 hash of the project directory.
5671

57-
When running ansible-dev-tools outside a virtual environment, our tools will
58-
display a warning message explaining the user that the isolation mode is
59-
disabled.
72+
## Offline mode
6073

61-
- No alteration of ansible environment variables will be made. This is different
62-
from the previous behaviors of ansible-lint or molecule, which tried to define
63-
these to point to a temporary directory.
74+
Tools like ansible-lint provide an option `--offline` that will disable their
75+
ability to install any dependencies. This does not mean that they will run
76+
successfully without the dependencies, it just means that they user takes
77+
the responsibility to pre-install these before running the tools.
6478

6579
---
6680

0 commit comments

Comments
 (0)