Opinion: When to (not) use fixtures for test data #11085
-
I sometimes see people excessively using fixtures for test data even for trivial cases, e.g.
IMHO this is an anti-pattern. There is little benefit in replacing one-liner data creation in tests (
Side-note: This pattern might have been learned from the very simplified examples in https://docs.pytest.org/en/7.3.x/how-to/fixtures.html#how-to-use-fixtures. Question: Does pytest have an opinion on when to (not) use fixtures for test data? If so, I suggest we add that to documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
There's no official opinion The reduced example you show unfortunately is a bit removed from practical use, the patterns looks similar to what Sometimes is used in university coursework If you have links to public code affected we would have a better basis for discussion |
Beta Was this translation helpful? Give feedback.
Fixture Start to shine whenever resources and parameterization come into play
They don't really help much if all you do is created single data classes
Once one Starts to actually put together set's of element with possible required cleanup the scales tip