Skip to content

Commit e6669f9

Browse files
amimasJohnVillalovos
authored andcommitted
docs(testing): document passing pytest options during local development
Added a section into the contributing docs to show how to pass options to `pytest`. This can be useful during local development for selecting specific tests. Running entire test suite is very time consuming.
1 parent 3eda669 commit e6669f9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CONTRIBUTING.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,32 @@ To cleanup the environment delete the container:
194194
docker rm -f gitlab-test
195195
docker rm -f gitlab-runner-test
196196
197+
Pass options to ``pytest``
198+
--------------------------
199+
200+
Options to ``pytest`` can be passed by adding them after ``--`` when running ``tox``:
201+
202+
.. code-block:: bash
203+
204+
tox -e api_func_v4 -- <pytest options>.
205+
206+
For example, you can use this to run a specific test. Running all tests can be time-consuming,
207+
so this allows you to focus on just the tests relevant to your changes. You can do this by passing
208+
the ``-k`` flag to ``pytest`` and setting a relevant expression to select the tests to run. For example:
209+
210+
.. code-block:: bash
211+
212+
# Run all API functional tests from the ``test_projects.py`` file:
213+
tox -e api_func_v4 -- --keep-containers -k test_projects.py
214+
215+
# Run only the ``test_get_project`` test method from the ``test_projects.py`` file:
216+
tox -e api_func_v4 -- --keep-containers -k "test_projects.py and test_create_project"
217+
218+
# The above will select all test methods start with ``test_create_project`` from the ``test_projects.py`` file.
219+
# To select only the ``test_create_project`` method, you can exclude other methods by using the ``not`` operator:
220+
tox -e api_func_v4 -- --keep-containers -k "test_projects.py and test_create_project and not test_create_project_"
221+
222+
197223
Rerunning failed CI workflows
198224
-----------------------------
199225

0 commit comments

Comments
 (0)