Skip to content

Allow to pass a callable condition to the flaky marker - #299

Merged
icemac merged 4 commits into
pytest-dev:masterfrom
alessio-locatelli:check_error_attributes
Aug 27, 2025
Merged

icemac merged 4 commits into
pytest-dev:masterfrom
alessio-locatelli:check_error_attributes

Conversation

@alessio-locatelli

Copy link
Copy Markdown
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.

@icemac icemac left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread docs/mark.rst Outdated
@icemac
icemac merged commit bd8cb4d into pytest-dev:master Aug 27, 2025
42 checks passed
@icemac

icemac commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

Thank you for this PR. 😃

@icemac

icemac commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

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

icemac commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

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