Skip to content

Commit 598d881

Browse files
committed
docs: document keyword argument support in marker expressions
1 parent 7c7c36d commit 598d881

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

doc/en/example/markers.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ You can "mark" a test function with custom metadata like this:
2525
pass # perform some webtest test for your app
2626
2727
28+
@pytest.mark.device(serial="123")
2829
def test_something_quick():
2930
pass
3031
3132
33+
@pytest.mark.device(serial="abc")
3234
def test_another():
3335
pass
3436
@@ -71,6 +73,28 @@ Or the inverse, running all tests except the webtest ones:
7173
7274
===================== 3 passed, 1 deselected in 0.12s ======================
7375
76+
.. _`marker_keyword_expression_example`:
77+
78+
Additionally, you can restrict a test run to only run tests matching one or multiple marker
79+
keyword arguments, e.g. to run only tests marked with ``device`` and the specific ``serial="123"``:
80+
81+
.. code-block:: pytest
82+
83+
$ pytest -v -m 'device(serial="123")'
84+
=========================== test session starts ============================
85+
platform linux -- Python 3.x.y, pytest-8.x.y, pluggy-1.x.y -- $PYTHON_PREFIX/bin/python
86+
cachedir: .pytest_cache
87+
rootdir: /home/sweet/project
88+
collecting ... collected 4 items / 3 deselected / 1 selected
89+
90+
test_server.py::test_something_quick PASSED [100%]
91+
92+
===================== 1 passed, 3 deselected in 0.12s ======================
93+
94+
.. note:: Only keyword argument matching is supported in marker expressions.
95+
96+
.. note:: Only ``int``, (unescaped) ``str``, ``bool`` & ``None`` values are supported in marker expressions.
97+
7498
Selecting tests based on their node ID
7599
--------------------------------------
76100

doc/en/how-to/usage.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,19 @@ Specifying a specific parametrization of a test:
7676
7777
**Run tests by marker expressions**
7878

79+
To run all tests which are decorated with the ``@pytest.mark.slow`` decorator:
80+
7981
.. code-block:: bash
8082
8183
pytest -m slow
8284
83-
Will run all tests which are decorated with the ``@pytest.mark.slow`` decorator.
85+
86+
To run all tests which are decorated with the annotated ``@pytest.mark.slow(phase=1)`` decorator,
87+
with the ``phase`` keyword argument set to ``1``:
88+
89+
.. code-block:: bash
90+
91+
pytest -m slow(phase=1)
8492
8593
For more information see :ref:`marks <mark>`.
8694

0 commit comments

Comments
 (0)