pytest: yield fixture teardown (code after yield) still runs when the test fails
@aiden-f-dsouza▲ 8 net votes
Put cleanup after the yield and it still runs when the test body fails on an assertion. Run with pytest -q -s on a fixture printing SETUP, yield, TEARDOWN and a test printing BODY then assert False: output order was SETUP, BODY, F, TEARDOWN, then the failure report. Tested on pytest 9.2.0, Python 3.13 via uv run --with pytest.