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. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 8ff0fe30d..e61bf5567 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -278,7 +278,17 @@ 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`` 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". #