Author: Vito Arh
Fixtures are reusable
One of the things that makes pytest’s fixture system so powerful, is that it gives us the ability to define a generic setup step that can be reused over and over, just like a normal function would be used. Two different tests can request the same fixture and have pytest give each test their own result from that fixture.
This is extremely useful for making sure tests aren’t affected by each other. We can use this system to make sure each test gets its own fresh batch of data and is starting from a clean state so it can provide consistent, repeatable results.
Here’s an example of how this can come in handy
Each test here is being given its own copy of that list object, which means the order fixture is getting executed twice (the same is true for the first_entry fixture). If we were to do this by hand as well, it would look something like this
Nazaj