Skip to content

Commit

Permalink
Always call after_request, even if request raises an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelboulton committed Mar 2, 2019
1 parent 5c26d5a commit 5062d6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions tavern/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,18 @@ def run_stage(sessions, stage, tavern_box, test_block_config):

logger.info("Running stage : %s", name)

hook_caller = test_block_config["tavern_internal"]["pytest_hook_caller"]

# These are run directly before/after to allow timing
test_block_config["tavern_internal"]["pytest_hook_caller"].pytest_tavern_before_request(stage=stage)
response = r.run()
test_block_config["tavern_internal"]["pytest_hook_caller"].pytest_tavern_after_request(stage=stage)
hook_caller.pytest_tavern_before_request(stage=stage)
try:
response = r.run()
finally:
# Called even if the test fails
hook_caller.pytest_tavern_after_request(stage=stage)

verifiers = get_verifiers(stage, test_block_config, sessions, expected)

for v in verifiers:
saved = v.verify(response)
test_block_config["variables"].update(saved)
Expand Down
7 changes: 6 additions & 1 deletion tavern/testutils/newhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ def pytest_tavern_before_request(stage):


def pytest_tavern_after_request(stage):
"""Called after each request"""
"""Called after each request, even if it fails
Note:
Some types of stages can run the request successfully, then fail later
on during verification.
"""

0 comments on commit 5062d6f

Please sign in to comment.