You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted my test to rerun only when it fails with an AssertionError to limit the scope of reruns. However, I found out that only_rerun="AssertionError" doesn't work when the AssertionError is raised by built-in assert statement.
It does work if I explicitly raise the error using raise AssertionError() but that's not how assertions are typically written in pytest.
assert (doesn't work)
$ pytest
========================= test session starts ==========================
<snip>
test_something.py F [100%]
=============================== FAILURES ===============================
____________________________ test_something ____________________________
@pytest.mark.flaky(only_rerun="AssertionError")
def test_something():
> assert False
E assert False
test_something.py:7: AssertionError
======================= short test summary info ========================
FAILED test_something.py::test_something - assert False
========================== 1 failed in 0.02s ===========================
AssertionError (works)
$ pytest
========================= test session starts ==========================
<snip>
test_something.py RF [100%]
=============================== FAILURES ===============================
____________________________ test_something ____________________________
@pytest.mark.flaky(only_rerun="AssertionError")
def test_something():
> raise AssertionError()
E AssertionError
test_something.py:6: AssertionError
======================= short test summary info ========================
FAILED test_something.py::test_something - AssertionError
====================== 1 failed, 1 rerun in 0.03s ======================
The text was updated successfully, but these errors were encountered:
yugokato
changed the title
only_rerun="AssertionError" doesn't trigger reruns when AssertionError is raised by the built-in assert statement
only_rerun="AssertionError" doesn't trigger reruns when AssertionError is raised by built-in assert statement
Apr 23, 2025
I wanted my test to rerun only when it fails with an
AssertionError
to limit the scope of reruns. However, I found out thatonly_rerun="AssertionError"
doesn't work when theAssertionError
is raised by built-inassert
statement.It does work if I explicitly raise the error using
raise AssertionError()
but that's not how assertions are typically written inpytest
.Environment:
pytest==8.3.5
pytest-rerunfailures==15.0
The text was updated successfully, but these errors were encountered: