-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Warn when a mark is applied to a fixture #8428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn when a mark is applied to a fixture #8428
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea to warn (and eventually error) on this. The code LGTM, with some comments.
Also, for deprecations doc/en/deprecations.rst
also needs to be updated.
src/_pytest/deprecated.py
Outdated
@@ -95,6 +95,8 @@ | |||
"see https://docs.pytest.org/en/latest/deprecations.html#node-fspath-in-favor-of-pathlib-and-node-path", | |||
) | |||
|
|||
MARKED_FIXTURE = PytestDeprecationWarning("Marks cannot be applied to fixtures") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this message more informative, e.g. "Marks applied to fixture functions have no effect. Use XYZ instead."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's not always a clean option, eg sometimes you want item.add_marker(
sometimes you want to use @pytest.fixture(params=[pytest.param(..., marks=...)])
and sometimes you want to add an explicit fixture dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is probably too much for the warning itself, but maybe in the deprecation doc, basically what you wrote above would be helpful I think. But OK if not.
3a439db
to
a7e0ae2
Compare
any progress here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @graingert ?
Co-authored-by: Bruno Oliveira <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
for more information, see https://pre-commit.ci
…o-a-fixture' into warn-when-a-mark-is-applied-to-a-fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and I'm keen to get it in soon - rebase and apply the minor comments below?
Co-authored-by: Zac Hatfield-Dodds <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @graingert! Looking forward to seeing how many people hit this new warning...
Requested changes implemented
Fixes #3664