docs: document keyword argument support in marker expressions
This commit is contained in:
parent
7c7c36d7e0
commit
598d881c9c
|
@ -25,10 +25,12 @@ You can "mark" a test function with custom metadata like this:
|
|||
pass # perform some webtest test for your app
|
||||
|
||||
|
||||
@pytest.mark.device(serial="123")
|
||||
def test_something_quick():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.device(serial="abc")
|
||||
def test_another():
|
||||
pass
|
||||
|
||||
|
@ -71,6 +73,28 @@ Or the inverse, running all tests except the webtest ones:
|
|||
|
||||
===================== 3 passed, 1 deselected in 0.12s ======================
|
||||
|
||||
.. _`marker_keyword_expression_example`:
|
||||
|
||||
Additionally, you can restrict a test run to only run tests matching one or multiple marker
|
||||
keyword arguments, e.g. to run only tests marked with ``device`` and the specific ``serial="123"``:
|
||||
|
||||
.. code-block:: pytest
|
||||
|
||||
$ pytest -v -m 'device(serial="123")'
|
||||
=========================== test session starts ============================
|
||||
platform linux -- Python 3.x.y, pytest-8.x.y, pluggy-1.x.y -- $PYTHON_PREFIX/bin/python
|
||||
cachedir: .pytest_cache
|
||||
rootdir: /home/sweet/project
|
||||
collecting ... collected 4 items / 3 deselected / 1 selected
|
||||
|
||||
test_server.py::test_something_quick PASSED [100%]
|
||||
|
||||
===================== 1 passed, 3 deselected in 0.12s ======================
|
||||
|
||||
.. note:: Only keyword argument matching is supported in marker expressions.
|
||||
|
||||
.. note:: Only ``int``, (unescaped) ``str``, ``bool`` & ``None`` values are supported in marker expressions.
|
||||
|
||||
Selecting tests based on their node ID
|
||||
--------------------------------------
|
||||
|
||||
|
|
|
@ -76,11 +76,19 @@ Specifying a specific parametrization of a test:
|
|||
|
||||
**Run tests by marker expressions**
|
||||
|
||||
To run all tests which are decorated with the ``@pytest.mark.slow`` decorator:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pytest -m slow
|
||||
|
||||
Will run all tests which are decorated with the ``@pytest.mark.slow`` decorator.
|
||||
|
||||
To run all tests which are decorated with the annotated ``@pytest.mark.slow(phase=1)`` decorator,
|
||||
with the ``phase`` keyword argument set to ``1``:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pytest -m slow(phase=1)
|
||||
|
||||
For more information see :ref:`marks <mark>`.
|
||||
|
||||
|
|
Loading…
Reference in New Issue