File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change
1
+ Expand docs on registering marks and the effect of ``--strict ``.
Original file line number Diff line number Diff line change @@ -26,12 +26,10 @@ which also serve as documentation.
26
26
:ref: `fixtures <fixtures >`.
27
27
28
28
29
- Raising errors on unknown marks: --strict
30
- -----------------------------------------
29
+ .. _unknown-marks :
31
30
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
+ -------------------------------
35
33
36
34
Marks can be registered in ``pytest.ini `` like this:
37
35
@@ -42,8 +40,10 @@ Marks can be registered in ``pytest.ini`` like this:
42
40
slow
43
41
serial
44
42
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 ``:
47
47
48
48
.. code-block :: ini
49
49
@@ -53,6 +53,9 @@ should add ``--strict`` to ``addopts``:
53
53
slow
54
54
serial
55
55
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
+
56
59
57
60
.. _marker-revamp :
58
61
Original file line number Diff line number Diff line change @@ -286,6 +286,26 @@ the plugin manager like this:
286
286
If you want to look at the names of existing plugins, use
287
287
the ``--trace-config `` option.
288
288
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
+
289
309
Testing plugins
290
310
---------------
291
311
You can’t perform that action at this time.
0 commit comments