Skip to content
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

--fail-on-flaky not compatible with mark usage #287

Closed
ricardo-passthrough opened this issue Feb 12, 2025 · 3 comments · Fixed by #288
Closed

--fail-on-flaky not compatible with mark usage #287

ricardo-passthrough opened this issue Feb 12, 2025 · 3 comments · Fixed by #288
Labels
help wanted a pull request to fix this issue is welcome

Comments

@ricardo-passthrough
Copy link
Contributor

ricardo-passthrough commented Feb 12, 2025

--fail-on-flaky only exits with code 7 if --reruns is passed via CLI. Otherwise it breaks the execution regardless of flakiness.

Also the implementation implies if I add --reruns i want this to always return exit status 7... this was not what I was expecting.

test_flaky.py:

@pytest.mark.flaky(reruns=10)
def test_flaky_test():
    assert True
$ pytest -k test_flaky_test --fail-on-flaky
...
File "$HOME/.local/share/virtualenvs/<venv>/lib/python3.9/site-packages/pytest_rerunfailures.py", line 632, in pytest_sessionfinish
    if session.config.getvalue("reruns") > 0:
TypeError: '>' not supported between instances of 'NoneType' and 'int'
@ricardo-passthrough
Copy link
Contributor Author

maybe something like this would work best:

@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
    if exitstatus != 0:
        return

    for item in session.items:
        if hasattr(item, "execution_count"):
            if item.execution_count > 1:
                session.exitstatus = 7
                break

@icemac
Copy link
Contributor

icemac commented Feb 13, 2025

Thank you for writing up the issue. A pull request would be welcome.

@icemac icemac added the help wanted a pull request to fix this issue is welcome label Feb 13, 2025
@ricardo-passthrough ricardo-passthrough changed the title --fail-on-flaky not compatible with fixture configuration --fail-on-flaky not compatible with mark usage Feb 13, 2025
@ricardo-passthrough
Copy link
Contributor Author

pushed a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted a pull request to fix this issue is welcome
Projects
None yet
2 participants