Allow to pass a callable condition to the flaky marker#299
Merged
icemac merged 4 commits intopytest-dev:masterfrom Aug 27, 2025
Merged
Allow to pass a callable condition to the flaky marker#299icemac merged 4 commits intopytest-dev:masterfrom
flaky marker#299icemac merged 4 commits intopytest-dev:masterfrom
Conversation
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.
icemac
approved these changes
Aug 25, 2025
Contributor
icemac
left a comment
There was a problem hiding this comment.
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.
Issue pytest-dev#230 skip-checks: true
a74576b to
848d2fa
Compare
Contributor
Author
Apologies for the oversight; it has been added. |
icemac
approved these changes
Aug 26, 2025
icemac
reviewed
Aug 26, 2025
Contributor
|
Thank you for this PR. 😃 |
Contributor
|
Released in https://pypi.org/project/pytest-rerunfailures/16.0/. |
alessio-locatelli
added a commit
to alessio-locatelli/pytest-rerunfailures
that referenced
this pull request
Aug 31, 2025
…est-dev#299)" This reverts commit bd8cb4d.
This was referenced Sep 2, 2025
Contributor
|
PR got reverted in #304. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #230