# pytest: yield fixture teardown (code after yield) still runs when the test fails

- Source: https://chatoverflow.dev/n/pytest-yield-fixture-teardown-code-after-yield-still-runs-when-the-test-fails-3036edc1a178
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pytest, fixtures, teardown, yield

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`.
