| 1 |
<!-- |
| 2 |
Copyright (c) Ansible Project |
| 3 |
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
--> |
| 6 |
|
| 7 |
# Contributing |
| 8 |
|
| 9 |
We follow [Ansible Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) in all our contributions and interactions within this repository. |
| 10 |
|
| 11 |
## Test pull requests |
| 12 |
|
| 13 |
If you want to test a PR locally, refer to [our testing guide](https://github.com/ansible/community-docs/blob/main/test_pr_locally_guide.rst) for instructions on how do it quickly. |
| 14 |
|
| 15 |
If you find any inconsistencies or places in this document which can be improved, feel free to raise an issue or pull request to fix it. |
| 16 |
|
| 17 |
## Run sanity or unit locally (with antsibull-nox) |
| 18 |
|
| 19 |
The easiest way to run sanity and unit tests locally is to use [antsibull-nox](https://ansible.readthedocs.io/projects/antsibull-nox/). |
| 20 |
(If you have [nox](https://nox.thea.codes/en/stable/) installed, it will automatically install antsibull-nox in a virtual environment for you.) |
| 21 |
|
| 22 |
### Sanity tests |
| 23 |
|
| 24 |
The following commands show how to run ansible-test sanity tests: |
| 25 |
|
| 26 |
```.bash |
| 27 |
# Run basic sanity tests for all files in the collection: |
| 28 |
nox -Re ansible-test-sanity-devel |
| 29 |
|
| 30 |
# Run basic sanity tests for the given files and directories: |
| 31 |
nox -Re ansible-test-sanity-devel -- plugins/modules/boot.py tests/unit/plugins/module_utils/ |
| 32 |
|
| 33 |
# Run all other sanity tests for all files in the collection: |
| 34 |
nox -R |
| 35 |
``` |
| 36 |
|
| 37 |
If you replace `-Re` with `-e`, respectively. |
| 38 |
If you leave `-R` away, then the virtual environments will be re-created. |
| 39 |
The `-R` re-uses them (if they already exist). |
| 40 |
|
| 41 |
### Unit tests |
| 42 |
|
| 43 |
The following commands show how to run unit tests: |
| 44 |
|
| 45 |
```.bash |
| 46 |
# Run all unit tests: |
| 47 |
nox -Re ansible-test-units-devel |
| 48 |
|
| 49 |
# Run all unit tests for one Python version (a lot faster): |
| 50 |
nox -Re ansible-test-units-devel -- --python 3.13 |
| 51 |
|
| 52 |
# Run a specific unit test (for the community.hrobot.boot module) for one Python version: |
| 53 |
nox -Re ansible-test-units-devel -- --python 3.13 tests/unit/plugins/modules/test_boot.py |
| 54 |
``` |
| 55 |
|
| 56 |
If you replace `-Re` with `-e`, then the virtual environments will be re-created. |
| 57 |
The `-R` re-uses them (if they already exist). |
| 58 |
|
| 59 |
## Run basic sanity, unit or integration tests locally (with ansible-test) |
| 60 |
|
| 61 |
Instead of using antsibull-nox, |
| 62 |
you can also run sanity and unit tests with ansible-test directly. |
| 63 |
|
| 64 |
You have to check out the repository into a specific path structure to be able to run `ansible-test`. |
| 65 |
The path to the git checkout must end with `.../ansible_collections/community/hrobot`. |
| 66 |
Please see [our testing guide](https://github.com/ansible/community-docs/blob/main/test_pr_locally_guide.rst) for instructions on how to check out the repository into a correct path structure. |
| 67 |
The short version of these instructions is: |
| 68 |
|
| 69 |
```.bash |
| 70 |
mkdir -p ~/dev/ansible_collections/community |
| 71 |
git clone https://github.com/ansible-collections/community.hrobot.git ~/dev/ansible_collections/community/hrobot |
| 72 |
cd ~/dev/ansible_collections/community/hrobot |
| 73 |
``` |
| 74 |
|
| 75 |
Then you can run `ansible-test` (which is a part of [ansible-core](https://pypi.org/project/ansible-core/)) inside the checkout. |
| 76 |
The following example commands expect that you have installed Docker or Podman. |
| 77 |
|
| 78 |
### Basic sanity tests |
| 79 |
|
| 80 |
The following commands show how to run basic sanity tests: |
| 81 |
|
| 82 |
```.bash |
| 83 |
# Run basic sanity tests for all files in the collection: |
| 84 |
ansible-test sanity --docker -v |
| 85 |
|
| 86 |
# Run basic sanity tests for the given files and directories: |
| 87 |
ansible-test sanity --docker -v plugins/modules/boot.py tests/unit/plugins/module_utils/ |
| 88 |
``` |
| 89 |
|
| 90 |
### Unit tests |
| 91 |
|
| 92 |
Note that for running unit tests, |
| 93 |
you need to install required collections in the same folder structure that `community.hrobot` is checked out in. |
| 94 |
Right now, you need to install [`community.internal_test_tools`](https://github.com/ansible-collections/community.internal_test_tools). |
| 95 |
If you want to use the latest version from GitHub, |
| 96 |
you can run: |
| 97 |
``` |
| 98 |
git clone https://github.com/ansible-collections/community.internal_test_tools.git ~/dev/ansible_collections/community/internal_test_tools |
| 99 |
``` |
| 100 |
|
| 101 |
The following commands show how to run unit tests: |
| 102 |
|
| 103 |
```.bash |
| 104 |
# Run all unit tests: |
| 105 |
ansible-test units --docker -v |
| 106 |
|
| 107 |
# Run all unit tests for one Python version (a lot faster): |
| 108 |
ansible-test units --docker -v --python 3.8 |
| 109 |
|
| 110 |
# Run a specific unit test (for the community.hrobot.boot module) for one Python version: |
| 111 |
ansible-test units --docker -v --python 3.8 tests/unit/plugins/modules/test_boot.py |
| 112 |
``` |