@@ -407,3 +407,33 @@ def pytest_runtest_logfinish(nodeid, location):
407407 """ .format (hook_message ))
408408 result = testdir .runpytest ('--reruns' , '1' , '-s' )
409409 result .stdout .fnmatch_lines (hook_message )
410+
411+ @pytest .mark .parametrize (
412+ "file_text, only_rerun_texts, should_rerun" ,
413+ [
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 ),
425+ ]
426+ )
427+ def test_only_rerun_flag (testdir , file_text , only_rerun_texts , should_rerun ):
428+ testdir .makepyfile (file_text )
429+
430+ num_failed = 1
431+ num_passed = 0
432+ num_reruns = 1
433+ num_reruns_actual = num_reruns if should_rerun else 0
434+
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 )
439+ assert_outcomes (result , passed = num_passed , failed = num_failed , rerun = num_reruns_actual )
0 commit comments