From 24fd2928780ea1f073d26a9ba415d62ff4101138 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 10 Oct 2022 12:28:14 +0100 Subject: [PATCH 1/4] Update changelog/3664.deprecation.rst Co-authored-by: Bruno Oliveira --- changelog/3664.deprecation.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog/3664.deprecation.rst b/changelog/3664.deprecation.rst index 6436910a6..0a00e26c1 100644 --- a/changelog/3664.deprecation.rst +++ b/changelog/3664.deprecation.rst @@ -1 +1,3 @@ -Applying a mark to a fixture function is deprecated. Doing so has no effect. +Applying a mark to a fixture function now issues a warning: marks in fixtures never had any effect, but it is a common user error to apply a mark to a fixture (for example ``usefixtures``) and expect it to work. + +This will become an error in the future. From d86df89a9291c29e19af3a762bd38bd959f1325c Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 10 Oct 2022 12:28:22 +0100 Subject: [PATCH 2/4] Update doc/en/deprecations.rst Co-authored-by: Bruno Oliveira --- doc/en/deprecations.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 8ff0fe30d..25be02d41 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -278,7 +278,18 @@ Applying a mark to a fixture function .. deprecated:: 7.2 -Applying a mark to a fixture function is deprecated. Doing so has no effect, and will raise an error in the next version. +Applying a mark to a fixture function never had any effect, but it is a common user error. + +.. code-block:: python + + @pytest.mark.usefixtures("clean_database") + @pytest.fixture + def user() -> User: + ... + +Users expected in this case that the ``usefixtures`` mark would have its intended effect of using the ``clean_database`` fixture when ``user`` was invoked, when in fact it has no effect at all. + +Now pytest will issue a warning when it encounters this problem, and will raise an error in the future versions. Backward compatibilities in ``Parser.addoption`` From 7759a9d3c2d6805f1e080512f40a3ada9207e66c Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 10 Oct 2022 12:28:30 +0100 Subject: [PATCH 3/4] Update src/_pytest/deprecated.py Co-authored-by: Bruno Oliveira --- src/_pytest/deprecated.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index d6b48a3c9..fb528e38b 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -107,7 +107,10 @@ HOOK_LEGACY_MARKING = UnformattedWarning( "#configuring-hook-specs-impls-using-markers", ) -MARKED_FIXTURE = PytestDeprecationWarning("Marks applied to fixtures have no effect") +MARKED_FIXTURE = PytestDeprecationWarning( + "Marks applied to fixtures have no effect\n" + "See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function" +) # You want to make some `__init__` or function "private". # From 0de2aa93f0e214341af40f63f498a0498cc07832 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 11:30:13 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/en/deprecations.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 25be02d41..e61bf5567 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -281,7 +281,6 @@ Applying a mark to a fixture function Applying a mark to a fixture function never had any effect, but it is a common user error. .. code-block:: python - @pytest.mark.usefixtures("clean_database") @pytest.fixture def user() -> User: