Skip to content

Allow flaky conditions to inspect failure exceptions - #365

Merged
icemac merged 2 commits into
pytest-dev:masterfrom
ryux1:fix/230-exception-aware-condition
Sep 9, 2026
Merged

Allow flaky conditions to inspect failure exceptions#365
icemac merged 2 commits into
pytest-dev:masterfrom
ryux1:fix/230-exception-aware-condition

Conversation

@ryux1

@ryux1 ryux1 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Closes #230

This lets flaky conditions make one rerun decision for an entire test attempt from the exceptions that caused its failed phases:

  • one-argument callable conditions receive each failure exception;
  • existing zero-argument callable conditions remain supported;
  • string conditions inspect the exception through the reserved error name;
  • setup, call, teardown, and subtest failures retain their corresponding exceptions;
  • an attempt is rerun when any failed phase matches, with each failure evaluated at most once.

ExceptionInfo stays on the worker-local test item, so xdist never serializes it, and the cached exception state is cleared after every attempt. Condition evaluation errors become non-fatal warnings even when warning filters promote warnings to errors.

Validation:

  • pytest 8.2, 8.3, and 8.4: 206 passed, 19 skipped in each environment
  • pytest 9.0 and 9.1: 216 passed, 9 skipped in each environment
  • pytest 9.1 with pytest-xdist: 225 passed
  • pre-commit run --all-files passed

@icemac

icemac commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The test failures against pytest-main are also on master and need to be fixed there before we can make progress here.

@icemac

icemac commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

master is fixed now, could you please resolve the conflicts?

@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.

Thanks for working on #230 — the xdist-safe approach of keeping ExceptionInfo on the worker-side item is the right idea. A few things need fixing before this can go in; two of them abort the whole run with INTERNALERROR, and one makes the feature a no-op for failed subtests. Details inline.

Comment created by Claude

Comment thread src/pytest_rerunfailures.py Outdated
Comment thread src/pytest_rerunfailures.py Outdated
Comment thread src/pytest_rerunfailures.py Outdated
Comment thread src/pytest_rerunfailures.py Outdated
Comment thread src/pytest_rerunfailures.py
Comment thread src/pytest_rerunfailures.py
Comment thread src/pytest_rerunfailures.py Outdated
Comment thread src/pytest_rerunfailures.py Outdated
Comment thread docs/mark.rst Outdated
Keep ExceptionInfo on the worker-side item so callable and string conditions can inspect failure attributes without breaking xdist report serialization. Cover matching and nonmatching call errors, setup and teardown failures, single evaluation, and the xdist regression.
@ryux1
ryux1 force-pushed the fix/230-exception-aware-condition branch from 9dfe284 to 04cb3ef Compare September 8, 2026 14:02
@icemac
icemac merged commit be14a6b into pytest-dev:master Sep 9, 2026
45 checks passed
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