Skip to content

Commit

Permalink
Add call of pytest_runtest_logfinish hook (#83).
Browse files Browse the repository at this point in the history
  • Loading branch information
KillAChicken authored and sallner committed Mar 26, 2019
1 parent 4097b8a commit 6db36cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def pytest_runtest_protocol(item, nextitem):
parallel = hasattr(item.config, 'slaveinput')
item.execution_count = 0

while True:
need_to_run = True
while need_to_run:
item.execution_count += 1
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid,
location=item.location)
Expand All @@ -195,7 +196,12 @@ def pytest_runtest_protocol(item, nextitem):

break # trigger rerun
else:
return True # no need to rerun
need_to_run = False

item.ihook.pytest_runtest_logfinish(nodeid=item.nodeid,
location=item.location)

return True


def pytest_report_teststatus(report):
Expand Down
12 changes: 12 additions & 0 deletions test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def pytest_runtest_teardown(item):
result = testdir.runpytest('--reruns', '2')
assert_outcomes(result, passed=3, rerun=2)


def test_rerun_report(testdir):
testdir.makepyfile('def test_pass(): assert False')
testdir.makeconftest("""
Expand All @@ -399,3 +400,14 @@ def pytest_runtest_logreport(report):
""")
result = testdir.runpytest('--reruns', '2')
assert_outcomes(result, failed=1, rerun=2, passed=0)


def test_pytest_runtest_logfinish_is_called(testdir):
hook_message = "Message from pytest_runtest_logfinish hook"
testdir.makepyfile('def test_pass(): pass')
testdir.makeconftest(r"""
def pytest_runtest_logfinish(nodeid, location):
print("\n{0}\n")
""".format(hook_message))
result = testdir.runpytest('--reruns', '1', '-s')
result.stdout.fnmatch_lines(hook_message)

0 comments on commit 6db36cc

Please sign in to comment.