Skip to content

Commit b263229

Browse files
committed
doc: add "Use pytest's strict mode" to good practices
1 parent 8c7be91 commit b263229

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

changelog/13823.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ The individual strictness options can be explicitly set to override the global :
88
If new strictness options are added in the future, they will also be automatically enabled by :confval:`strict`.
99
Therefore, we only recommend setting ``strict=True`` if you're using a locked version of pytest,
1010
or if you want to proactively adopt new strictness options as they are added.
11+
12+
See :ref:`strict mode` for more details.

doc/en/explanation/goodpractices.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,73 @@ A list of the lints detected by flake8-pytest-style can be found on its `PyPI pa
329329
.. note::
330330

331331
flake8-pytest-style is not an official pytest project. Some of the rules enforce certain style choices, such as using `@pytest.fixture()` over `@pytest.fixture`, but you can configure the plugin to fit your preferred style.
332+
333+
.. _`strict mode`:
334+
335+
Using pytest's strict mode
336+
--------------------------
337+
338+
Pytest contains a set of configuration options that make it more strict.
339+
The options are off by default for compatibility or other reasons,
340+
but you should enable them if you can.
341+
342+
You can enable all of the strictness options at once by setting the :confval:`strict` configuration option:
343+
344+
.. tab:: toml
345+
346+
.. code-block:: toml
347+
348+
[pytest]
349+
strict = true
350+
351+
.. tab:: ini
352+
353+
.. code-block:: ini
354+
355+
[pytest]
356+
strict = true
357+
358+
See the :confval:`strict` for the options it enables and their effect.
359+
360+
If pytest adds new strictness options in the future, they will also be enabled by ``strict``.
361+
Therefore, you should only use ``strict`` if you use a locked version of pytest,
362+
or are prepared to fix occasional problems as new pytest versions are released.
363+
If you don't want to automatically pick up new options, you can enable options individually::
364+
365+
.. tab:: toml
366+
367+
.. code-block:: toml
368+
369+
[pytest]
370+
strict_config = true
371+
strict_markers = true
372+
strict_parametrization_ids = true
373+
strict_xfail = true
374+
375+
.. tab:: ini
376+
377+
.. code-block:: ini
378+
379+
[pytest]
380+
strict_config = true
381+
strict_markers = true
382+
strict_parametrization_ids = true
383+
strict_xfail = true
384+
385+
If you want to use strict mode but having trouble with a specific option, you can turn it off individually::
386+
387+
.. tab:: toml
388+
389+
.. code-block:: toml
390+
391+
[pytest]
392+
strict = true
393+
strict_parametrization_ids = false
394+
395+
.. tab:: ini
396+
397+
.. code-block:: ini
398+
399+
[pytest]
400+
strict = true
401+
strict_parametrization_ids = false

0 commit comments

Comments
 (0)