Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Update 08_request_finalizers.md #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tutorials/08_request_finalizers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pytest -vs tests/07_request_finalizer_test.py

As usual, we can see that our fixture runs first (including a "risky" function call), followed by our test case, and finally our safe_cleanup function. One advantage of this approach is that we can re-use a shared cleanup function, but the main benefit is that even if our fixture fails to initialize, our finalizer "cleanup" function still gets run!

To really see the finalizer in action, uncomment line 11 in `07_request_finalizer_test.py` (e.g. the commented-out "raise Exception" call), and re-run the test using the command above.
To really see the finalizer in action, uncomment line 26 in `07_request_finalizer_test.py` (e.g. the commented-out "raise Exception" call), and re-run the test using the command above.

That "risky" function didn't work out - it derailed our fixture, and our test case never even ran! But despite all that, our `safe_cleanup` function still got called.

And in a real test, with a fixture that sets up something complicated or expensive (and might fail _after_ it has made some kind of a mess), guaranteed cleanup could be a really important distinction!

### Up Next:

[Intro to Parameters](https://github.com/pluralsight/intro-to-pytest/blob/master/tutorials/09_intro_to_parameters.md)
[Intro to Parameters](https://github.com/pluralsight/intro-to-pytest/blob/master/tutorials/09_intro_to_parameters.md)