|
| 1 | +# Test Isolation |
| 2 | + |
| 3 | +!!! note |
| 4 | + |
| 5 | + The test isolation behaviors described below are expected to be fully implemented |
| 6 | + by the end of **February 2025** and will affect [ansible-lint][ansible-lint], [molecule][molecule] and [ansible-dev-environment (ade)][ansible-dev-environment] in particular. |
| 7 | + |
| 8 | +One very common problem in software development is reproducibility of test |
| 9 | +results across the various environments: |
| 10 | + |
| 11 | +- local development, aka "works on my machine" |
| 12 | +- CI/CD testing pipelines |
| 13 | +- staging and production environments |
| 14 | + |
| 15 | +A very common source of producing divergent results across these are the |
| 16 | +dependencies, which can be: |
| 17 | + |
| 18 | +- used dependencies that are not declared but happen to be installed |
| 19 | + on a developer's machine |
| 20 | +- different versions of the same dependency |
| 21 | +- conflicts between dependencies |
| 22 | + |
| 23 | +Historically, most of ansible-dev-tools tried to address these by installing |
| 24 | +dependencies in a controlled way and trying to avoid installing them in the |
| 25 | +default user home directory, as this might affect other projects in |
| 26 | +an unpredictable way. |
| 27 | + |
| 28 | +Starting with early 2025, all ansible-dev-tools will aim to implement the |
| 29 | +following predictable behaviors: |
| 30 | + |
| 31 | +- Prefer being run from within a python virtual environment, warning the user |
| 32 | + if this not the case. |
| 33 | +- Dynamically modify Ansible environment to prefer installation of dependencies |
| 34 | + such as collections, roles and python packages inside the current virtual |
| 35 | + environment. |
| 36 | + |
| 37 | +## Isolated mode (virtual environment) \[default\] |
| 38 | + |
| 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. |
| 42 | + |
| 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. |
| 46 | + |
| 47 | +When running ansible-dev-tools inside a virtual environment, the following |
| 48 | +things will happen: |
| 49 | + |
| 50 | +- Few Ansible environment variables will be automatically defined in order to |
| 51 | + 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. |
| 53 | +- Dependencies will automatically be installed inside the virtual environment |
| 54 | + |
| 55 | +## Non-isolated mode (outside virtual environments) |
| 56 | + |
| 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. |
| 60 | + |
| 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. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +[moleclue]: https://ansible.readthedocs.io/projects/molecule/ |
| 68 | +[ansible-lint]: https://ansible.readthedocs.io/projects/lint/ |
| 69 | +[ansible-dev-environment]: https://ansible.readthedocs.io/projects/dev-environment/ |
0 commit comments