Skip to content

Commit f628f43

Browse files
authored
Merge pull request #13852 from bluetech/strict-good-practice
doc: add "Use pytest's strict mode" to good practices
2 parents 6f9c628 + d68eba9 commit f628f43

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

changelog/13823.feature.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
Added a :confval:`strict` configuration option to enable all strictness-related options.
22

3-
When set to ``True``, the :confval:`strict` option currently enables :confval:`strict_config`,
4-
:confval:`strict_markers`, :confval:`strict_xfail`, and :confval:`strict_parametrization_ids`.
3+
When set to ``true``, the :confval:`strict` option currently enables
4+
5+
* :confval:`strict_config`
6+
* :confval:`strict_markers`
7+
* :confval:`strict_parametrization_ids`
8+
* :confval:`strict_xfail`
59

610
The individual strictness options can be explicitly set to override the global :confval:`strict` setting.
711

8-
If new strictness options are added in the future, they will also be automatically enabled by :confval:`strict`.
9-
Therefore, we only recommend setting ``strict=True`` if you're using a locked version of pytest,
12+
The previously-deprecated ``--strict`` command-line flag now enables strict mode.
13+
14+
If pytest adds new strictness options in the future, they will also be enabled in strict mode.
15+
Therefore, you should only enable strict mode if you use a pinned/locked version of pytest,
1016
or if you want to proactively adopt new strictness options as they are added.
17+
18+
See :ref:`strict mode` for more details.

doc/en/explanation/goodpractices.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,75 @@ 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+
.. versionadded:: 9.0
339+
340+
Pytest contains a set of configuration options that make it more strict.
341+
The options are off by default for compatibility or other reasons,
342+
but you should enable them if you can.
343+
344+
You can enable all of the strictness options at once by setting the :confval:`strict` configuration option:
345+
346+
.. tab:: toml
347+
348+
.. code-block:: toml
349+
350+
[pytest]
351+
strict = true
352+
353+
.. tab:: ini
354+
355+
.. code-block:: ini
356+
357+
[pytest]
358+
strict = true
359+
360+
See the :confval:`strict` documentation for the options it enables and their effect.
361+
362+
If pytest adds new strictness options in the future, they will also be enabled in strict mode.
363+
Therefore, you should only enable strict mode if you use a pinned/locked version of pytest,
364+
or if you want to proactively adopt new strictness options as they are added.
365+
If you don't want to automatically pick up new options, you can enable options individually::
366+
367+
.. tab:: toml
368+
369+
.. code-block:: toml
370+
371+
[pytest]
372+
strict_config = true
373+
strict_markers = true
374+
strict_parametrization_ids = true
375+
strict_xfail = true
376+
377+
.. tab:: ini
378+
379+
.. code-block:: ini
380+
381+
[pytest]
382+
strict_config = true
383+
strict_markers = true
384+
strict_parametrization_ids = true
385+
strict_xfail = true
386+
387+
If you want to use strict mode but having trouble with a specific option, you can turn it off individually::
388+
389+
.. tab:: toml
390+
391+
.. code-block:: toml
392+
393+
[pytest]
394+
strict = true
395+
strict_parametrization_ids = false
396+
397+
.. tab:: ini
398+
399+
.. code-block:: ini
400+
401+
[pytest]
402+
strict = true
403+
strict_parametrization_ids = false

doc/en/reference/reference.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ passed multiple times. The expected format is ``name=value``. For example::
24742474

24752475
.. confval:: strict
24762476

2477-
If set to ``true``, enables all strictness options:
2477+
If set to ``true``, enable "strict mode", which enables the following options:
24782478

24792479
* :confval:`strict_config`
24802480
* :confval:`strict_markers`
@@ -2486,16 +2486,16 @@ passed multiple times. The expected format is ``name=value``. For example::
24862486
If you explicitly set an individual strictness option, it takes precedence over ``strict``.
24872487

24882488
.. note::
2489-
If new strictness options are added to pytest in the future, they will also be enabled by ``strict``.
2490-
We therefore only recommend using this option when using a locked version of pytest,
2489+
If pytest adds new strictness options in the future, they will also be enabled in strict mode.
2490+
Therefore, you should only enable strict mode if you use a pinned/locked version of pytest,
24912491
or if you want to proactively adopt new strictness options as they are added.
24922492

24932493
.. tab:: toml
24942494

24952495
.. code-block:: toml
24962496
24972497
[pytest]
2498-
xfail_strict = true
2498+
strict = true
24992499
25002500
.. tab:: ini
25012501

0 commit comments

Comments
 (0)