@@ -199,6 +199,63 @@ def test_run_fails_with_code_1_after_consistent_test_failure_even_with_fail_on_f
199
199
assert result .ret == 1
200
200
201
201
202
+ def test_run_mark_and_fail_on_flaky_fails_with_custom_error_code_after_pass_on_rerun (
203
+ testdir ,
204
+ ):
205
+ testdir .makepyfile (f"""
206
+ import pytest
207
+
208
+ @pytest.mark.flaky(reruns=1)
209
+ def test_fail():
210
+ { temporary_failure ()}
211
+ """ )
212
+ result = testdir .runpytest ("--fail-on-flaky" )
213
+ assert_outcomes (result , passed = 1 , rerun = 1 )
214
+ assert result .ret == 7
215
+
216
+
217
+ def test_run_fails_with_code_1_after_test_failure_with_fail_on_flaky_and_mark (
218
+ testdir ,
219
+ ):
220
+ testdir .makepyfile ("""
221
+ import pytest
222
+
223
+ @pytest.mark.flaky(reruns=2)
224
+ def test_fail():
225
+ assert False
226
+ """ )
227
+ result = testdir .runpytest ("--fail-on-flaky" )
228
+ assert_outcomes (result , passed = 0 , failed = 1 , rerun = 2 )
229
+ assert result .ret == 1
230
+
231
+
232
+ def test_run_with_mark_and_fail_on_flaky_succeeds_if_all_tests_pass_without_reruns (
233
+ testdir ,
234
+ ):
235
+ testdir .makepyfile ("""
236
+ import pytest
237
+
238
+ @pytest.mark.flaky(reruns=2)
239
+ def test_marked_pass():
240
+ assert True
241
+
242
+ def test_unmarked_pass():
243
+ assert True
244
+ """ )
245
+ result = testdir .runpytest ("--fail-on-flaky" )
246
+ assert_outcomes (result , passed = 2 , rerun = 0 )
247
+ assert result .ret == pytest .ExitCode .OK
248
+
249
+
250
+ def test_run_with_fail_on_flaky_succeeds_if_all_tests_pass_without_reruns (
251
+ testdir ,
252
+ ):
253
+ testdir .makepyfile ("def test_pass(): assert True" )
254
+ result = testdir .runpytest ("--reruns" , "1" , "--fail-on-flaky" )
255
+ assert_outcomes (result , passed = 1 , rerun = 0 )
256
+ assert result .ret == pytest .ExitCode .OK
257
+
258
+
202
259
@pytest .mark .skipif (not has_xdist , reason = "requires xdist with crashitem" )
203
260
def test_rerun_passes_after_temporary_test_crash (testdir ):
204
261
# note: we need two tests because there is a bug where xdist
0 commit comments