You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
10. Update your local default branch. Assuming that it is ``main``:
72
+
10. Update your local default branch. If your default branch is ``main``, run:
78
73
79
74
.. code-block:: bash
80
75
@@ -90,81 +85,93 @@ Prepare your environment
90
85
Change the code
91
86
===============
92
87
93
-
.. note::
88
+
Do not combine multiple unrelated bug fixes or features in a single pull request. Instead, use separate pull requests for different changes.
94
89
95
-
Do NOT mix several bug fixes or features that are not tightly related in one pull request. Use separate pull requests for different changes.
90
+
Start by writing integration and unit tests, if applicable. These tests can verify that a bug exists before you apply your code fix and confirm that your code fixed the bug once the tests pass.
96
91
97
-
You should start with writing integration and unit tests if applicable. These can verify the bug exists (prior to your code fix) and verify your code fixed that bug once the tests pass.
92
+
Add integration tests
93
+
---------------------
98
94
99
95
.. note::
100
96
101
-
If there are any difficulties with writing or running the tests or you are not sure if the case can be covered, you can skip this step. Other contributors can help you with tests later if needed.
97
+
* Some collections do not have integration tests. In such cases, unit tests are highly recommended.
98
+
* If you have difficulty writing or running tests, or you are unsure if a case can be covered, skip this step. Other contributors can help you with tests later if needed.
102
99
103
-
.. note::
100
+
All integration tests reside in ``tests/integration/targets`` subdirectories.
104
101
105
-
Some collections do not have integration tests. In this case, unit tests are required.
102
+
Navigate to the subdirectory that contains the name of the module you plan to change.
103
+
For example, if you are fixing the ``mysql_user`` module in the ``community.mysql`` collection, its tests are in ``tests/integration/targets/test_mysql_user/tasks``.
106
104
107
-
All integration tests are stored in ``tests/integration/targets`` subdirectories.
108
-
Go to the subdirectory containing the name of the module you are going to change.
109
-
For example, if you are fixing the ``mysql_user`` module in the ``community.mysql`` collection,
110
-
its tests are in ``tests/integration/targets/test_mysql_user/tasks``.
105
+
The ``main.yml`` file contains test tasks and includes other test files.
106
+
Look for a suitable existing test file to integrate your tests, or create and include a dedicated test file.
107
+
You can use an existing test file as a template.
111
108
112
-
The ``main.yml`` file holds test tasks and includes other test files.
113
-
Look for a suitable test file to integrate your tests or create and include a dedicated test file.
114
-
You can use one of the existing test files as a draft.
115
-
116
-
When fixing a bug, write a task that reproduces the bug from the issue.
117
-
118
-
Put the reported case in the tests, then run integration tests with the following command:
109
+
When you fix a bug, write a task that reproduces the bug from the reported issue.
110
+
Then run integration tests by using the following command:
If you are unsure whether to use the default image or a specific image for testing, skip this step. The community can assist you later. You can also inspect the collection repository's CI to determine which containers it uses.
134
+
135
+
If the tests run successfully, two outcomes are possible:
136
+
137
+
* If the bug has not appeared and the tests passed, ask the reporter for more details. The issue might not be a bug, or it might relate to a specific software version or the reporter's local environment configuration.
138
+
* The bug appeared, and the tests failed as expected, showing the reported symptoms.
139
+
140
+
Add unit tests
141
+
--------------
140
142
141
143
.. note::
142
144
143
-
If you are not sure whether you should use the default image for testing or a specific one, skip the entire step - the community can help you later. You can also try to use the collection repository's CI to figure out which containers are used.
145
+
* Some collections do not have unit tests. In such cases, focus on integration tests.
146
+
* If you have difficulty writing or running tests, or you are unsure if a case can be covered, skip this step. Other contributors can help you with tests later if needed.
147
+
148
+
We recommend that you cover all changes with unit tests.
144
149
145
-
If the tests run successfully, there are usually two possible outcomes:
150
+
* **Location**: All unit tests are located in the ``tests/unit/`` directory.
151
+
* **Adding Tests**:
146
152
147
-
- If the bug has not appeared and the tests have passed successfully, ask the reporter to provide more details. It may not be a bug or can relate to a particular software version used or specifics of the reporter's local environment configuration.
148
-
- The bug has appeared and the tests have failed as expected showing the reported symptoms.
153
+
* Find an existing test file that corresponds to the code you are modifying.
154
+
* If a relevant file doesn't exist, create a new one.
155
+
* Use ``Pytest`` as testing framework.
149
156
150
-
Fix the bug
151
-
=============
157
+
See the :ref:`test_your_changes` section for detailed instructions on how to run the unit tests.
152
158
153
-
See :ref:`module_contribution` for some general guidelines about Ansible module development that may help you craft a good code fix for the bug.
159
+
.. _test_your_changes:
154
160
155
161
Test your changes
156
162
=================
157
163
158
-
1. Install ``flake8`` (``pip install flake8``, or install the corresponding package on your operating system).
164
+
To test your changes, complete the following steps:
165
+
166
+
1. Install ``flake8``.
159
167
160
168
2. Run ``flake8`` against a changed file:
161
169
162
170
.. code-block:: bash
163
171
164
172
$ flake8 path/to/changed_file.py
165
173
166
-
167
-
This shows unused imports, which are not shown by sanity tests, as well as other common issues.
174
+
This command identifies unused imports, which sanity tests do not show, and other common issues.
168
175
Optionally, you can use the ``--max-line-length=160`` command-line argument.
You can use the ``-vv`` or ``-vvv`` argument if you need more detailed output.
192
199
200
+
Two possible outcomes are:
193
201
194
-
There are two possible outcomes:
195
-
196
-
- They have failed. Look at the output of the command. Fix the problem in the code and run again. Repeat the cycle until the tests pass.
197
-
- They have passed. Remember they failed originally? Our congratulations! You have fixed the bug.
202
+
* The tests failed. Examine the command's output. Fix the problem in the code and run the tests again. Repeat this cycle until the tests pass.
203
+
* The tests passed. If they originally failed, you have successfully fixed the bug.
198
204
199
-
In addition to the integration tests, you can also cover your changes with unit tests. This is often required when integration tests are not applicable to the collection.
205
+
5. In addition to integration tests, you can also cover your changes with unit tests. This is often necessary when integration tests do not apply to the collection.
200
206
201
207
We use `pytest <https://docs.pytest.org/en/latest/>`_ as a testing framework.
202
208
203
-
Files with unit tests are stored in the ``tests/unit/plugins/`` directory. If you want to run unit tests, say, for ``tests/unit/plugins/test_myclass.py``, the command is:
209
+
Unit test files are in the ``tests/unit/plugins/`` directory. To run unit tests, for example, for ``tests/unit/plugins/test_myclass.py``, use the following command:
204
210
205
211
.. code-block:: bash
206
212
207
213
$ ansible-test units tests/unit/plugins/test_myclass.py --docker
208
214
209
-
If you want to run all unit tests available in the collection, run:
215
+
To run all available unit tests in the collection, run:
210
216
211
217
.. code-block:: bash
212
218
@@ -215,7 +221,9 @@ If you want to run all unit tests available in the collection, run:
215
221
Submit a pull request
216
222
=====================
217
223
218
-
1. Commit your changes with an informative but short commit message:
224
+
To submit a pull request, complete the following steps:
225
+
226
+
1. Commit your changes with a concise and informative commit message:
219
227
220
228
.. code-block:: bash
221
229
@@ -232,19 +240,15 @@ Submit a pull request
232
240
233
241
4. Click the :guilabel:`Pull requests` tab.
234
242
235
-
GitHub is tracking your fork, so it should see the new branch in it and automatically offer to create a pull request. Sometimes GitHub does not do it, and you should click the :guilabel:`New pull request` button yourself. Then choose :guilabel:`compare across forks` under the:guilabel:`Compare changes` title.
243
+
GitHub tracks your fork and should automatically offer to create a pull request for your new branch. If GitHub does not do this, click the :guilabel:`New pull request` button yourself. Then, under the :guilabel:`Compare changes` title, choose:guilabel:`compare across forks`.
236
244
237
245
5. Choose your repository and the new branch you pushed in the right drop-down list. Confirm.
238
246
239
-
a. Fill out the pull request template with all the information you want to mention.
240
-
241
-
b. Put ``Fixes + link to the issue`` in the pull request's description.
242
-
243
-
c. Put ``[WIP] + short description`` in the pull request's title. Mention the name of the module/plugin you are modifying at the beginning of the description.
247
+
a. Complete the pull request template with all relevant information.
248
+
b. Add ``Fixes + link to the issue`` in the pull request's description.
249
+
c. Click :guilabel:`Create pull request`.
244
250
245
-
d. Click :guilabel:`Create pull request`.
246
-
247
-
6. Add a :ref:`changelog fragment <collection_changelog_fragments>` to the ``changelogs/fragments`` directory. It will be published in release notes, so users will know about the fix.
251
+
6. Add a :ref:`changelog fragment <collection_changelog_fragments>` to the ``changelogs/fragments`` directory. This fragment will be published in the release notes, informing users about the fix.
248
252
249
253
a. Run the sanity test for the fragment:
250
254
@@ -261,12 +265,10 @@ Submit a pull request
261
265
$ git commit -m "Add changelog fragment"
262
266
$ git push origin name_of_my_branch
263
267
264
-
7. Verify the CI tests that run automatically on Red Hat infrastructure are successful after every commit.
265
-
266
-
You will see the CI status at the bottom of your pull request. If they are green and you think that you do not want to add more commits before someone should take a closer look at it, remove ``[WIP]`` from the title. Mention the issue reporter in a comment and let contributors know that the pull request is "Ready for review".
268
+
7. Verify that the CI tests, which run automatically on Red Hat infrastructure, are successful.
267
269
268
-
8. Wait for reviews. You can also ask for a review in the ``#ansible-community`` :ref:`Matrix/Libera.Chat IRC channel <communication_irc>`.
270
+
You will see the CI status at the bottom of your pull request. If the tests are green and you do not plan to add more commits, add a "Ready for review" comment.
269
271
270
-
9. If the pull request looks good to the community, committers will merge it.
272
+
8. If the pull request looks good to the community, committers will merge it. You can mention them explicitly.
271
273
272
-
For more in-depth details on this process, see the :ref:`Ansible developer guide <developer_guide>`.
274
+
For more detailed information on this process, see the :ref:`Ansible developer guide <developer_guide>`.
0 commit comments