From 6d07db38a046fc3480f151edebf860228370d91f Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sat, 1 Aug 2020 21:35:16 -0400 Subject: [PATCH 1/3] ensure that we call pytest_runtest_logreport for all reports of tests --- pytest_rerunfailures.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pytest_rerunfailures.py b/pytest_rerunfailures.py index 13cb985..6b4fb35 100644 --- a/pytest_rerunfailures.py +++ b/pytest_rerunfailures.py @@ -226,40 +226,44 @@ def pytest_runtest_protocol(item, nextitem): parallel = hasattr(item.config, "slaveinput") item.execution_count = 0 - need_to_run = True - while need_to_run: + need_to_rerun = True + while need_to_rerun: item.execution_count += 1 item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) reports = runtestprotocol(item, nextitem=nextitem, log=False) + need_to_rerun = False for report in reports: # 3 reports: setup, call, teardown is_terminal_error = _should_hard_fail_on_error(item.session.config, report) + out_of_runs = item.execution_count > reruns report.rerun = item.execution_count - 1 xfail = hasattr(report, "wasxfail") if ( - item.execution_count > reruns + out_of_runs or not report.failed or xfail or is_terminal_error + or need_to_rerun ): - # last run or no failure detected, log normally + # out of rerun attempts, no errors detected, or we're finishing off + # the reports of a filed test log normally item.ihook.pytest_runtest_logreport(report=report) else: # failure detected and reruns not exhausted, since i < reruns + need_to_rerun = True report.outcome = "rerun" - time.sleep(delay) if not parallel or works_with_current_xdist(): # will rerun test, log intermediate result item.ihook.pytest_runtest_logreport(report=report) - # cleanin item's cashed results from any level of setups - _remove_cached_results_from_failed_fixtures(item) - _remove_failed_setup_state_from_session(item) + if need_to_rerun: + # at least one report failed and we have reruns rerun the test + time.sleep(delay) - break # trigger rerun - else: - need_to_run = False + # cleanin item's cashed results from any level of setups + _remove_cached_results_from_failed_fixtures(item) + _remove_failed_setup_state_from_session(item) item.ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) From 2685d80b77cd26518ae2bcf3d8bf10f804b3bdd1 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sat, 1 Aug 2020 21:42:42 -0400 Subject: [PATCH 2/3] Add changelog entry --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index d1c77a6..5e056a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,10 @@ Changelog (`#117 `_) (PR from `@gnikonorov`_) +- Ensure ``pytest_runtest_logreport`` is called for all reports in a test. + (`#108 `_) + (PR from `@gnikonorov`_) + .. _@gnikonorov: https://github.com/gnikonorov From 97806ab7d41b8b9e79328fcb43d845fd0d1298ae Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sat, 1 Aug 2020 21:49:39 -0400 Subject: [PATCH 3/3] fixup some comments --- pytest_rerunfailures.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pytest_rerunfailures.py b/pytest_rerunfailures.py index 6b4fb35..eaa24df 100644 --- a/pytest_rerunfailures.py +++ b/pytest_rerunfailures.py @@ -246,7 +246,7 @@ def pytest_runtest_protocol(item, nextitem): or need_to_rerun ): # out of rerun attempts, no errors detected, or we're finishing off - # the reports of a filed test log normally + # the reports of a failed test, log normally item.ihook.pytest_runtest_logreport(report=report) else: # failure detected and reruns not exhausted, since i < reruns @@ -258,7 +258,8 @@ def pytest_runtest_protocol(item, nextitem): item.ihook.pytest_runtest_logreport(report=report) if need_to_rerun: - # at least one report failed and we have reruns rerun the test + # at least one report failed and we have reruns left + # prepare to rerun the test time.sleep(delay) # cleanin item's cashed results from any level of setups