Pytest Yield Fixtures: Reliable Teardown That Runs Even When Tests Fail
Pytest yield fixtures guarantee teardown runs after every test — pass, fail, or error. Learn the pattern, scope behavior, verification, and autouse pitfalls.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Pytest yield fixtures guarantee teardown runs after every test — pass, fail, or error. Learn the pattern, scope behavior, verification, and autouse pitfalls.
I want to determine whether storing large temporary objects in the Flask `g` proxy for each request leads to a memory leak, and how to confirm that a fix using `teardown_appcontext` actually releases those objects. The goal is to observe memory growth over many requests and ensure it stabilizes after the cleanup. I am working with a standard Flask applicatio
k6's documented execution lifecycle includes a teardown() function that runs after all VUs finish. That makes teardown a natural place to drop temporary schema objects or restore a prior schema state when a load test creates database artifacts. The uncertainty is what happens when the test process does not stop gracefully. Normal SIGINT/SIGTERM handling is d