2 ms·
One thing I've encounter with pytest fixtures is they have a tendency to balloon in size. We started out with like 50 fixtures, but now we have a conftest.py f
by emptysea 6y ago
One thing I've encounter with pytest fixtures is they have a tendency to balloon in size.
We started out with like 50 fixtures, but now we have a conftest.py file that has `institution_1`, ..., `institution_10`.
My end conclusion is that fixtures are nice for some things, like managing mocks, and clearing the databases after tests, but for data it's better to write some functions to create stuff.
So instead of `def test_something(institution_with_some_flag_b)` you'd write in your test body:
def test_something() -> None:
institution = create_institution(some_flag="b")
Also another benefit is you can click into the function whereas fixtures you have to grep.
- sirlantis 6y agoI’ve rewritten a bunch of our tests to this factory pattern last week, too (the factory is a fixture though - FactoryBoy is worth a look). I’d argue that too many global fixtures in conftest have a high risk of becoming a “Mystery Guests” or too general fixtures. For a test reader it’s impossible to know the semantics of “institution_10”. I believe this to be rooted in DRY obsession leading to coupling of tests: “We need a second institution in two modules? Let’s lift it up to global!”