From 3a88adb3202c3fb230b485280e75eb716916d150 Mon Sep 17 00:00:00 2001 From: Sadra Barikbin Date: Sun, 17 Sep 2023 10:31:17 +0330 Subject: [PATCH] Add changelog and note --- changelog/11284.deprecation.rst | 3 +++ doc/en/deprecations.rst | 14 ++++++++++++++ src/_pytest/deprecated.py | 8 ++++---- testing/deprecated_test.py | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 changelog/11284.deprecation.rst diff --git a/changelog/11284.deprecation.rst b/changelog/11284.deprecation.rst new file mode 100644 index 000000000..12bcbdc56 --- /dev/null +++ b/changelog/11284.deprecation.rst @@ -0,0 +1,3 @@ +Accessing ``item.funcargs`` with fixture names other than the direct ones, i.e. the direct args, the ones with ``autouse`` and the ones with ``usefixtures`` issues a warning. + +This will become an error in pytest 9. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 76cc3482a..c7c04f859 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -278,6 +278,20 @@ The accompanying ``py.path.local`` based paths have been deprecated: plugins whi resolved in future versions as we slowly get rid of the :pypi:`py` dependency (see :issue:`9283` for a longer discussion). +.. _item-funcargs-deprecation: + +Accessing ``item.funcargs`` with not directly requested fixture names +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 8.0 +.. versionremoved:: 9.0 + +Accessing ``item.funcargs`` with not directly requested fixture names issues warning and +will be erroneous starting from pytest 9. Directly requested fixtures are the direct args +to the test, the ``usefixtures`` fixtures and the ``autouse`` ones. + +To request fixtures other than the directly requested ones, user could use +``request.getfixturevalue`` instead. .. _nose-deprecation: diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index c513675a7..aae277705 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -50,10 +50,10 @@ MARKED_FIXTURE = PytestRemovedIn9Warning( ) ITEM_FUNCARGS_MEMBERS = PytestRemovedIn9Warning( - "Access to names other than initialnames i.e., direct args," - " the ones with `usefixture` or the ones with `autouse` through " - "`item.funcargs` is deprecated and will raise `KeyError` from " - "pytest 9. Please use `request.getfixturevalue` instead." + "Accessing `item.funcargs` with a fixture name not directly requested" + " by the item, through a direct argument, `usefixtures` marker or" + " an `autouse` fixture, is deprecated and will raise KeyError starting" + " from pytest 9. Please use request.getfixturevalue instead." ) # You want to make some `__init__` or function "private". diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 36b878df9..56fee570a 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -217,7 +217,7 @@ def test_deprecated_access_to_item_funcargs(pytester: Pytester) -> None: test.setup() with pytest.warns( pytest.PytestRemovedIn9Warning, - match=r"Access to names other than initialnames", + match=r"Accessing `item.funcargs` with a fixture", ) as record: test.funcargs["fixture1"] assert len(record) == 1