`rerun_filter` called twice per test
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- testing-qa
Research direction
Start with flaky_pytest_plugin.py, especially pytest_runtest_protocol, call_and_report, and add_failure, then trace _should_rerun_test in _flaky_plugin.py. Reproduce the issue with the sample test and pytest. Done means rerun_filter is invoked once per test run while rerun behavior remains correct.
Written by the indexing model from the issue text.
Description
I am finding that the rerun_filter function is called twice per test.
Version: 3.6.1
Pytest version: 5.4.3
Here is some sample code to recreate the problem:
def my_rerun_filter(*args):
log.debug("ran filter")
return True
runs = 0
class TestFlaky:
@flaky(max_runs=10, rerun_filter=my_rerun_filter)
def test_4_fails(self):
global runs
runs += 1
log.debug("ran test {}".format(runs))
if runs < 5:
raise ValueError()
This logs ran filter 8 times even though the test only runs 4 times. A stack trace shows that the flaky_pytest_plugin.py will call self._should_rerun_test twice: once at line 92 and once at line 101.
Relevant stack traces:
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/flaky_pytest_plugin.py", line 92, in pytest_runtest_protocol
self.runner.pytest_runtest_protocol(item, nextitem)
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/_pytest/runner.py", line 85, in pytest_runtest_protocol
runtestprotocol(item, nextitem=nextitem)
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/_pytest/runner.py", line 100, in runtestprotocol
reports.append(call_and_report(item, "call", log))
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/flaky_pytest_plugin.py", line 141, in call_and_report
if self._will_handle_test_error_or_failure(item, name, err):
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/_flaky_plugin.py", line 152, in _will_handle_test_error_or_failure
return self._should_handle_test_error_or_failure(test) and self._should_rerun_test(test, name, err)
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/flaky_pytest_plugin.py", line 101, in pytest_runtest_protocol
should_rerun = not skipped and self.add_failure(item, call_info.excinfo)
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/flaky_pytest_plugin.py", line 327, in add_failure
return self._handle_test_error_or_failure(item, error)
File "/Users/rwoo/rwoo/lib/python3.6/site-packages/flaky/_flaky_plugin.py", line 190, in _handle_test_error_or_failure
if self._should_rerun_test(test, name, err):
- Dominant language
- Python
- Stars
- 397
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from box/flaky
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100