Skip to content

only_rerun="AssertionError" doesn't trigger reruns when AssertionError is raised by built-in assert statement #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yugokato opened this issue Apr 23, 2025 · 1 comment · May be fixed by #293

Comments

@yugokato
Copy link

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 ======================

Environment:
pytest==8.3.5
pytest-rerunfailures==15.0

@yugokato 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
@yugokato
Copy link
Author

yugokato commented Apr 23, 2025

FYI - I've just opened a PR that fixes the issue I mentioned. Please feel free to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant