Skip to content

Commit 642949e

Browse files
amimasJohnVillalovos
authored andcommitted
docs: add instructions for passing pytest options
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. Removed earlier instructions for the same purpose as they are no longer valid.
1 parent 48193ee commit 642949e

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

CONTRIBUTING.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ You need to install ``tox`` (``pip3 install tox``) to run tests and lint checks
111111
# run unit tests in one python environment only (useful for quick testing during development):
112112
tox -e py311
113113
114-
# run a specific unit test file:
115-
tox -e py311 -- tests/unit/objects/test_projects.py
116-
117114
# run unit and smoke tests in one python environment only
118115
tox -e py312,smoke
119116
@@ -151,15 +148,9 @@ To run these tests:
151148
# run the CLI tests:
152149
tox -e cli_func_v4
153150
154-
# run a specific CLI functional test file:
155-
tox -e cli_func_v4 -- tests/functional/cli/test_cli_v4.py
156-
157151
# run the python API tests:
158152
tox -e api_func_v4
159153
160-
# run a specific API functional test file:
161-
tox -e api_func_v4 -- tests/functional/api/test_projects.py
162-
163154
When developing tests it can be a little frustrating to wait for GitLab to spin
164155
up every run. To prevent the containers from being cleaned up afterwards, pass
165156
``--keep-containers`` to pytest, i.e.:
@@ -203,6 +194,32 @@ To cleanup the environment delete the container:
203194
docker rm -f gitlab-test
204195
docker rm -f gitlab-runner-test
205196
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+
206223
Rerunning failed CI workflows
207224
-----------------------------
208225

0 commit comments

Comments
 (0)