Skip to content

Commit 6db36cc

Browse files
KillAChickensallner
authored andcommitted
Add call of pytest_runtest_logfinish hook (#83).
1 parent 4097b8a commit 6db36cc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pytest_rerunfailures.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def pytest_runtest_protocol(item, nextitem):
168168
parallel = hasattr(item.config, 'slaveinput')
169169
item.execution_count = 0
170170

171-
while True:
171+
need_to_run = True
172+
while need_to_run:
172173
item.execution_count += 1
173174
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid,
174175
location=item.location)
@@ -195,7 +196,12 @@ def pytest_runtest_protocol(item, nextitem):
195196

196197
break # trigger rerun
197198
else:
198-
return True # no need to rerun
199+
need_to_run = False
200+
201+
item.ihook.pytest_runtest_logfinish(nodeid=item.nodeid,
202+
location=item.location)
203+
204+
return True
199205

200206

201207
def pytest_report_teststatus(report):

test_pytest_rerunfailures.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def pytest_runtest_teardown(item):
389389
result = testdir.runpytest('--reruns', '2')
390390
assert_outcomes(result, passed=3, rerun=2)
391391

392+
392393
def test_rerun_report(testdir):
393394
testdir.makepyfile('def test_pass(): assert False')
394395
testdir.makeconftest("""
@@ -399,3 +400,14 @@ def pytest_runtest_logreport(report):
399400
""")
400401
result = testdir.runpytest('--reruns', '2')
401402
assert_outcomes(result, failed=1, rerun=2, passed=0)
403+
404+
405+
def test_pytest_runtest_logfinish_is_called(testdir):
406+
hook_message = "Message from pytest_runtest_logfinish hook"
407+
testdir.makepyfile('def test_pass(): pass')
408+
testdir.makeconftest(r"""
409+
def pytest_runtest_logfinish(nodeid, location):
410+
print("\n{0}\n")
411+
""".format(hook_message))
412+
result = testdir.runpytest('--reruns', '1', '-s')
413+
result.stdout.fnmatch_lines(hook_message)

0 commit comments

Comments
 (0)