Skip to content

Commit 7fc0283

Browse files
cluster2600patchback[bot]
authored andcommitted
doc: fix removed pytest.config reference in historical-notes (#14216)
pytest.config was removed in pytest 5.0, but the documentation on 'Conditions as strings instead of booleans' still showed it as the modern equivalent of string-based skipif conditions. Replace the broken example with the current recommended approach using request.config (via an autouse fixture), and add a note pointing to the removal notice in the deprecations page. Fixes #12377 (cherry picked from commit 9fd1eeb)
1 parent 3065de7 commit 7fc0283

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

doc/en/historical-notes.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,24 @@ configuration value which you might have added:
263263
@pytest.mark.skipif("not config.getvalue('db')")
264264
def test_function(): ...
265265
266-
The equivalent with "boolean conditions" is:
266+
The equivalent with "boolean conditions" using ``request.config`` is:
267267

268268
.. code-block:: python
269269
270-
@pytest.mark.skipif(not pytest.config.getvalue("db"), reason="--db was not specified")
270+
@pytest.fixture(autouse=True)
271+
def skip_if_no_db(request):
272+
if not request.config.getoption("--db", default=False):
273+
pytest.skip("--db was not specified")
274+
275+
271276
def test_function():
272277
pass
273278
274279
.. note::
275280

276-
You cannot use ``pytest.config.getvalue()`` in code
277-
imported before pytest's argument parsing takes place. For example,
278-
``conftest.py`` files are imported before command line parsing and thus
279-
``config.getvalue()`` will not execute correctly.
281+
``pytest.config`` was removed in pytest 5.0. Use ``request.config``
282+
(via the ``request`` fixture) or the ``pytestconfig`` fixture instead.
283+
See :ref:`pytest.config global deprecated` for details.
280284

281285
``pytest.set_trace()``
282286
----------------------

0 commit comments

Comments
 (0)