Skip to content

Commit 4fc1085

Browse files
committed
switch only-rerun flag to append action instead of store
1 parent f95a0b9 commit 4fc1085

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

pytest_rerunfailures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def pytest_addoption(parser):
3333
"re-run failing tests to eliminate flaky failures")
3434
group._addoption(
3535
'--only-rerun',
36-
action='store',
36+
action='append',
3737
dest='only_rerun',
3838
type=str,
3939
default=None,
40-
help='Optional comma separated list. If passed, only rerun errors matching the regexes provided.'
40+
help='If passed, only rerun errors matching the regex provided. Pass this flag multiple times to accumulate a list of regexes to match'
4141
)
4242
group._addoption(
4343
'--reruns',
@@ -190,7 +190,7 @@ def _should_hard_fail_on_error(session_config, report):
190190
if not rerun_errors:
191191
return False
192192

193-
for rerun_regex in rerun_errors.split(','):
193+
for rerun_regex in rerun_errors:
194194
if re.search(rerun_regex, report.longrepr.reprcrash.message):
195195
return False
196196

test_pytest_rerunfailures.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -409,27 +409,31 @@ def pytest_runtest_logfinish(nodeid, location):
409409
result.stdout.fnmatch_lines(hook_message)
410410

411411
@pytest.mark.parametrize(
412-
"file_text, only_rerun_text, should_rerun",
412+
"file_text, only_rerun_texts, should_rerun",
413413
[
414-
('def test_only_rerun(): raise AssertionError("ERR")', 'AssertionError', True),
415-
('def test_only_rerun(): raise AssertionError("ERR")', 'Assertion*', True),
416-
('def test_only_rerun(): raise AssertionError("ERR")', 'Assertion', True),
417-
('def test_only_rerun(): raise AssertionError("ERR")', 'ValueError', False),
418-
('def test_only_rerun(): raise AssertionError("ERR")', 'AssertionError,ValueError', True),
419-
('def test_only_rerun(): raise AssertionError("ERR")', 'AssertionError ValueError', False),
420-
('def test_only_rerun(): raise AssertionError("ERR")', '', True),
421-
('def test_only_rerun(): raise AssertionError("ERR")', 'AssertionError: ', True),
422-
('def test_only_rerun(): raise AssertionError("ERR")', 'AssertionError: ERR', True),
423-
('def test_only_rerun(): raise AssertionError("ERR")', 'ERR', True),
414+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError'], True),
415+
('def test_only_rerun(): raise AssertionError("ERR")', ['Assertion*'], True),
416+
('def test_only_rerun(): raise AssertionError("ERR")', ['Assertion'], True),
417+
('def test_only_rerun(): raise AssertionError("ERR")', ['ValueError'], False),
418+
('def test_only_rerun(): raise AssertionError("ERR")', [''], True),
419+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError: '], True),
420+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError: ERR'], True),
421+
('def test_only_rerun(): raise AssertionError("ERR")', ['ERR'], True),
422+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError,ValueError'], False),
423+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError ValueError'], False),
424+
('def test_only_rerun(): raise AssertionError("ERR")', ['AssertionError','ValueError'], True),
424425
]
425426
)
426-
def test_only_rerun_flag(testdir, file_text, only_rerun_text, should_rerun):
427+
def test_only_rerun_flag(testdir, file_text, only_rerun_texts, should_rerun):
427428
testdir.makepyfile(file_text)
428429

429430
num_failed = 1
430431
num_passed = 0
431432
num_reruns = 1
432433
num_reruns_actual = num_reruns if should_rerun else 0
433434

434-
result = testdir.runpytest('--reruns', str(num_reruns), '--only-rerun', only_rerun_text)
435+
pytest_args = ['--reruns', str(num_reruns)]
436+
for only_rerun_text in only_rerun_texts:
437+
pytest_args.extend(['--only-rerun', only_rerun_text])
438+
result = testdir.runpytest(*pytest_args)
435439
assert_outcomes(result, passed=num_passed, failed=num_failed, rerun=num_reruns_actual)

0 commit comments

Comments
 (0)