Skip to content

Conversation

@alessio-locatelli
Copy link
Contributor

Closes #230

This introduces a condition parameter to the `@pytest.mark.flaky`
decorator, allowing for more granular control over when a test is rerun.

The condition can be a callable or a string.

If it's a callable, it will be passed the exception object from the
failed test. The test will be rerun only if the callable returns True.

If it's a string, it will be evaluated with the following objects in
its global context: os, sys, platform, config, and error (the
exception instance). The test will be rerun only if the string
evaluates to True.

Exceptions raised by a condition callable are now caught and logged as a
warning, preventing the test suite from crashing.
Copy link
Contributor

@icemac icemac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the code. Could you please add a change log entry referencing the issue or this PR? This would make it perfect for merge and release.

@alessio-locatelli
Copy link
Contributor Author

I like the code. Could you please add a change log entry referencing the issue or this PR? This would make it perfect for merge and release.

Apologies for the oversight; it has been added.

@icemac icemac merged commit bd8cb4d into pytest-dev:master Aug 27, 2025
42 checks passed
@icemac
Copy link
Contributor

icemac commented Aug 27, 2025

Thank you for this PR. 😃

@icemac
Copy link
Contributor

icemac commented Aug 29, 2025

alessio-locatelli added a commit to alessio-locatelli/pytest-rerunfailures that referenced this pull request Aug 31, 2025
icemac pushed a commit that referenced this pull request Sep 2, 2025
* Revert "Allow to pass a callable condition to the `flaky` marker (#299)"

This reverts commit bd8cb4d.
@icemac
Copy link
Contributor

icemac commented Sep 2, 2025

PR got reverted in #304.

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 this pull request may close these issues.

For "only_rerun" allow access exception attributes

2 participants