Skip to content

Commit bcc08ff

Browse files
committed
More docs on registering marks
1 parent ba1fc02 commit bcc08ff

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

changelog/4935.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expand docs on registering marks and the effect of ``--strict``.

doc/en/mark.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ which also serve as documentation.
2626
:ref:`fixtures <fixtures>`.
2727

2828

29-
Raising errors on unknown marks: --strict
30-
-----------------------------------------
29+
.. _unknown-marks:
3130

32-
When the ``--strict`` command-line flag is passed, any unknown marks applied
33-
with the ``@pytest.mark.name_of_the_mark`` decorator will trigger an error.
34-
Marks defined or added by pytest or by a plugin will not trigger an error.
31+
Raising errors on unknown marks
32+
-------------------------------
3533

3634
Marks can be registered in ``pytest.ini`` like this:
3735

@@ -42,8 +40,10 @@ Marks can be registered in ``pytest.ini`` like this:
4240
slow
4341
serial
4442
45-
This can be used to prevent users mistyping mark names by accident. Test suites that want to enforce this
46-
should add ``--strict`` to ``addopts``:
43+
When the ``--strict`` command-line flag is passed, any unknown marks applied
44+
with the ``@pytest.mark.name_of_the_mark`` decorator will trigger an error.
45+
Marks added by pytest or by a plugin instead of the decorator will not trigger
46+
this error. To enforce a limited set of markers, add ``--strict`` to ``addopts``:
4747

4848
.. code-block:: ini
4949
@@ -53,6 +53,9 @@ should add ``--strict`` to ``addopts``:
5353
slow
5454
serial
5555
56+
Third-party plugins should always :ref:`register their markers <registering-markers>`
57+
so that they appear in pytest's help text and do not emit warnings.
58+
5659

5760
.. _marker-revamp:
5861

doc/en/writing_plugins.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ the plugin manager like this:
286286
If you want to look at the names of existing plugins, use
287287
the ``--trace-config`` option.
288288

289+
290+
.. _registering-markers:
291+
292+
Registering custom markers
293+
--------------------------
294+
295+
If your plugin uses any markers, you should register them so that they appear in
296+
pytest's help text and do not :ref:`cause spurious warnings <unknown-marks>`.
297+
For example, the following plugin would register ``cool_marker`` and
298+
``mark_with`` for all users:
299+
300+
.. code-block:: python
301+
302+
def pytest_configure(config):
303+
config.addinivalue_line("markers", "cool_marker: this one is for cool tests.")
304+
config.addinivalue_line(
305+
"markers", "mark_with(arg, arg2): this marker takes arguments."
306+
)
307+
308+
289309
Testing plugins
290310
---------------
291311

0 commit comments

Comments
 (0)