pytest: Generate an error when a mark is applied to a fixture
Follow up from #1014.
We should generate an error if a @pytest.mark
is applied to a fixture.
There is a warning in doc/en/fixture.rst
about this problem which should be updated once this issue is dealt with.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 23
- Comments: 28 (18 by maintainers)
Commits related to this issue
- backups: tests: Fix issue with usage of fixture 'needs_root' Fixtures cannot be currently included into other fixtures by using @pytest.mark.fixtures('fixture_name') They have to be included as param... — committed to RalfBarkow/Plinth by JosephNuthalapati2244 5 years ago
- Warn when a mark is applied to a fixture Fixes #3664 — committed to graingert/pytest by graingert 3 years ago
- Warn when a mark is applied to a fixture Fixes #3664 — committed to graingert/pytest by graingert 3 years ago
- Warn when a mark is applied to a fixture Fixes #3664 — committed to graingert/pytest by graingert 3 years ago
- Warn when a mark is applied to a fixture Fixes #3664 — committed to graingert/pytest by graingert 3 years ago
I don’t understand why applying the
usefixtures
marker to a fixture should result in an error. Fixtures can already use other fixtures by declaring them in the signature:What is the reason of not supporting the equivalent way with
usefixtures
?The reason I am asking this is that in pytest-factoryboy we have to call exec in order to generate a fixture that requires all the relevant fixtures. The use of
exec
could be easily avoided if it was possible to mark a fixture with theusefixtures
marker.EDIT: I made a typo that changed the polarity of the sentence “What is the reason of not supporting the equivalent way with
usefixtures
?”Just to mention that I stubbed my toe on this very problem today. My tests miraculously were failing when applying a fixture using
mark
but when used directly it was fine. It took a while to debug the cause and find this thread. Think it would be great to have at least the warning merged a.s.a.p. and even better would be to actually support this behavior. I would have helped out with a PR but haven’t developedpytest
yet, maybe in the future though.@nicoddemus I am starting working on this.