Warn when a mark is applied to a fixture#8428
Conversation
bluetech
left a comment
There was a problem hiding this comment.
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
| "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.
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.
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.
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? |
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
for more information, see https://pre-commit.ci
…o-a-fixture' into warn-when-a-mark-is-applied-to-a-fixture
Zac-HD
left a comment
There was a problem hiding this comment.
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 <zac.hatfield.dodds@gmail.com>
Zac-HD
left a comment
There was a problem hiding this comment.
Thanks, @graingert! Looking forward to seeing how many people hit this new warning...
Requested changes implemented
* Updated environment lockfiles * Don't decorate a fixture - pytest-dev/pytest#8428 . * Clearer use of skip_data(). --------- Co-authored-by: Lockfile bot <noreply@github.com>
Fixes #3664