Skip to content

Commit

Permalink
[FEAT] Added execution_count variable to expose the number of a test …
Browse files Browse the repository at this point in the history
…executions. Simplified a general loop logic a bit.
  • Loading branch information
OlegKuzovkov authored and sallner committed Sep 17, 2018
1 parent e83cfb5 commit 4ec7431
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ def pytest_runtest_protocol(item, nextitem):
check_options(item.session.config)
delay = get_reruns_delay(item)
parallel = hasattr(item.config, 'slaveinput')
item.execution_count = 0

for i in range(reruns + 1): # ensure at least one run of each item
while True:
item.execution_count += 1
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid,
location=item.location)
reports = runtestprotocol(item, nextitem=nextitem, log=False)

for report in reports: # 3 reports: setup, test, teardown
report.rerun = i
for report in reports: # 3 reports: setup, call, teardown
xfail = hasattr(report, 'wasxfail')
if i == reruns or not report.failed or xfail:
if item.execution_count > reruns or not report.failed or xfail:
# last run or no failure detected, log normally
item.ihook.pytest_runtest_logreport(report=report)
else:
Expand All @@ -164,8 +165,6 @@ def pytest_runtest_protocol(item, nextitem):
else:
return True # no need to rerun

return True


def pytest_report_teststatus(report):
"""Adapted from https://pytest.org/latest/_modules/_pytest/skipping.html
Expand Down
9 changes: 9 additions & 0 deletions test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,12 @@ def test_fail_two():
time.sleep.assert_called_with(delay_time)

assert_outcomes(result, passed=0, failed=1, rerun=2)


def test_execution_count_exposed(testdir):
testdir.makepyfile('def test_pass(): assert True')
testdir.makeconftest("""
def pytest_runtest_teardown(item):
assert item.execution_count == 3""")
result = testdir.runpytest('--reruns', '2')
assert_outcomes(result, passed=3, rerun=2)

0 comments on commit 4ec7431

Please sign in to comment.