Using cache
Usually we testers like to think about each test as being as independent as possible from other tests. We want to make sure order dependencies don’t creep in. We want to be able to run or rerun any test in any order and get the same result. We also want test sessions to be repeatable and to not change behavior based on previous test sessions.
However, sometimes passing information from one test session to the next can be quite useful. When we do want to pass information to future test sessions, we can do it with the cache builtin fixture.
The cache fixture is all about storing information about one test session and retrieving it in the next. A great example of using the powers of cache for good is the builtin functionality of
Get Python Testing with pytest now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.