Repository navigation
Restore higher-scoped teardown when a teardown error rules out a re-run - #356
Conversation
220c83b to
6c3f95f
Compare
pytest_runtest_teardown takes the module, class and session finalizers off the setup stack when it expects a re-run. The error a teardown raises is only classified as terminal afterwards, in pytest_runtest_makereport, so that decision cannot see it. With --rerun-except or --only-rerun matching that error the protocol then declines to re-run, nothing puts the finalizers back, and the higher-scoped fixture teardown is skipped for the rest of the session. Make the hook a wrapper so it can look at the error the teardown phase raised, and when that error rules out a re-run, put the finalizers back and tear down what the item was the last user of.
icemac
left a comment
There was a problem hiding this comment.
Reviewed against real repro cases (pytest 9.1.1) and the full suite with and without xdist + subtests (179 passed).
The first comment below is a regression against this PR's own goal, so it is the one that matters; the rest are on the new error-chaining path.
Also checked and clean: module/class fixture preservation when the next item shares the scope, terminal teardown error on the second attempt, and stack ordering after stack.update(suspended_finalizers). test_run_session_teardown_once_after_reruns fails under pytest 8.2, but identically on master — pre-existing, not from this PR.
— Comment created by Claude
|
Pushed as a new commit. It reads smaller than it sounds: The exception group needs 183 passed on 3.13 with pytest 9.1.1, same under |
The teardown hookwrapper had to work out whether a teardown error rules out a re-run before pytest built the report for the phase, so it re-derived the answer from the raw exception. That second derivation disagreed with pytest_runtest_makereport for every error pytest does not report as a failure: pytest.skip() and pytest.xfail() in a teardown were classified as terminal, the higher-scoped fixtures were torn down, and then the test was re-run anyway. Move the restore and the teardown into pytest_runtest_makereport, which already has the report and _terminal_errors, and drop _is_terminal_error. There is one derivation now, so the two cannot disagree. Run the second teardown through CallInfo.from_call with the same reraise as pytest, so an Exit or a KeyboardInterrupt from a higher-scoped finalizer still ends the session instead of being swallowed. When both teardowns fail, report them as a BaseExceptionGroup the way pytest does for several failing finalizers, rather than assigning __context__, which was lost whenever the first error was raised with "from None".
…roup (#16852) Bumps the python-testing group with 1 update: [pytest-rerunfailures](https://github.com/pytest-dev/pytest-rerunfailures). Updates `pytest-rerunfailures` from 16.6 to 16.6.1 <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-rerunfailures/blob/master/CHANGES.rst">pytest-rerunfailures's changelog</a>.</em></p> <blockquote> <h2>16.6.1 (2026-09-03)</h2> <p>Bug Fixes +++++++++</p> <ul> <li>Ensure teardown reports are passed to <code>pytest_runtest_logreport</code> for rerun attempts. (<code>[#237](pytest-dev/pytest-rerunfailures#237) <https://github.com/pytest-dev/pytest-rerunfailures/issues/237></code>_)</li> <li>Prevent superseded built-in subtest failures from remaining in the final test result when rerunning tests with pytest-xdist. (<code>[#350](pytest-dev/pytest-rerunfailures#350) <https://github.com/pytest-dev/pytest-rerunfailures/issues/350></code>_)</li> <li>Restore module, class, and session scoped fixture teardown when a <code>flaky</code> marker condition is falsy. (<code>[#351](pytest-dev/pytest-rerunfailures#351) <https://github.com/pytest-dev/pytest-rerunfailures/issues/351></code>_)</li> <li>Restore module, class, and session scoped fixture teardown when an error raised during teardown rules out a re-run. (<code>[#356](pytest-dev/pytest-rerunfailures#356) <https://github.com/pytest-dev/pytest-rerunfailures/issues/356></code>_)</li> <li>Keep module, class, and session scoped fixtures alive across re-runs of a test whose call phase failed through subtests only. (<code>[#357](pytest-dev/pytest-rerunfailures#357) <https://github.com/pytest-dev/pytest-rerunfailures/issues/357></code>_)</li> <li>Authenticate xdist StatusDB connections with a per-session token. (<code>[#358](pytest-dev/pytest-rerunfailures#358) <https://github.com/pytest-dev/pytest-rerunfailures/issues/358></code>_)</li> <li>Ensure negative rerun counts do not skip the initial test execution. (<code>[#359](pytest-dev/pytest-rerunfailures#359) <https://github.com/pytest-dev/pytest-rerunfailures/issues/359></code>_)</li> </ul> <p>Misc ++++</p> <ul> <li>Replace deprecated <code>Config.getvalue()</code> calls with <code>Config.getoption()</code>. (<code>[#345](pytest-dev/pytest-rerunfailures#345) <https://github.com/pytest-dev/pytest-rerunfailures/issues/345></code>_)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/dad07a7f360e96c0cbbc4301e36cdc439eb9a36b"><code>dad07a7</code></a> Preparing release 16.6.1</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/968fb6c1d3982ea35f041ecb62024e79016324bb"><code>968fb6c</code></a> Prevent negative reruns from skipping initial execution (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/360">#360</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/367df9044cbcf3bbf153269bdab995e1f9eb113c"><code>367df90</code></a> Keep higher-scoped fixtures alive across re-runs of failed subtests (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/357">#357</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/69ac0a7e66f1f55c1e94a2f237e2659250795ef7"><code>69ac0a7</code></a> Authenticate xdist StatusDB connections (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/358">#358</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/20decd37b22736b1a92ecb7a6ed598e7fd70cff1"><code>20decd3</code></a> Restore higher-scoped teardown when a teardown error rules out a re-run (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/356">#356</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/84af73d63c1ac3eeeeba73a5e3ac91a44078c7bb"><code>84af73d</code></a> Fix subtest rerun reporting with xdist (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/352">#352</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/d784cdda0b946c8788939255b6b72df67da82a19"><code>d784cdd</code></a> Test with pytest-xdist on CI (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/354">#354</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/9f85e063dac5387cb0b17ffcb8aadeca545292a8"><code>9f85e06</code></a> Restore higher-scoped teardown when a flaky condition is falsy (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/351">#351</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/eab650fb2a2665d61539aafda81ae549440c2834"><code>eab650f</code></a> Test rerun-except for setup errors (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/349">#349</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/0b0843a83fb7e79c37e626092a77c5f7cd49f4df"><code>0b0843a</code></a> Fix only_rerun marker precedence test (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/348">#348</a>)</li> <li>Additional commits viewable in <a href="https://github.com/pytest-dev/pytest-rerunfailures/compare/16.6...16.6.1">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Lockfile-only test dependency patch with bug fixes; low impact outside pytest rerun/xdist paths. > > **Overview** > Updates the locked **`pytest-rerunfailures`** dependency from **16.6** to **16.6.1** in `uv.lock` (sdist/wheel URLs and hashes only). No `pyproject.toml` or application code changes. > > The new patch release mainly fixes rerun/teardown behavior (higher-scoped fixtures, subtests, xdist reporting) and adds a per-session token for xdist StatusDB connections. CI that uses `--reruns` or the `flaky` marker should see more reliable fixture lifecycle and reporting. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4ad93d6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…with 4 updates (#415) Bumps the python-development group with 4 updates in the / directory: [ipython](https://github.com/ipython/ipython), [pytest-randomly](https://github.com/pytest-dev/pytest-randomly), [pytest-rerunfailures](https://github.com/pytest-dev/pytest-rerunfailures) and [ruff](https://github.com/astral-sh/ruff). Updates `ipython` from 9.16.1 to 9.17.1 <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/ipython/ipython/commit/48ff02957a9a0cdb30a63e15f6493e583e9ec54b"><code>48ff029</code></a> release 9.17.1</li> <li><a href="https://github.com/ipython/ipython/commit/ed47107a5218bfc6419fe5f2a79ebda22a77d612"><code>ed47107</code></a> Have builin-lazy magics have a lower priority than registered on.</li> <li><a href="https://github.com/ipython/ipython/commit/19f9ae0a863c21cff52fa07c74b18fc5b482d9c3"><code>19f9ae0</code></a> back to dev</li> <li><a href="https://github.com/ipython/ipython/commit/3278f6f5b71b3152e084478cac8fa20405c49b5a"><code>3278f6f</code></a> release 9.17.0</li> <li><a href="https://github.com/ipython/ipython/commit/40cfb95e634b8807ff66dac1a269610794f7da66"><code>40cfb95</code></a> Update what's new for 9.17</li> <li><a href="https://github.com/ipython/ipython/commit/2ed42ae6a01e77c8a11ead7b168ceb920f4cb563"><code>2ed42ae</code></a> Fix RST formatting in display_functions.py</li> <li><a href="https://github.com/ipython/ipython/commit/a487a06bb1193f4d166210153e7068af694ec2ae"><code>a487a06</code></a> change emojis</li> <li><a href="https://github.com/ipython/ipython/commit/7f0ee55684f08f5af18190aa58d4bb3018fb20d2"><code>7f0ee55</code></a> Declare IPython's built-in magics lazily</li> <li><a href="https://github.com/ipython/ipython/commit/ee0239282e9439ea181a723187ede0cc55475414"><code>ee02392</code></a> Only run the psutil-free kitty detection test where /proc exists</li> <li><a href="https://github.com/ipython/ipython/commit/af386cf710668a2f81abdae3621a8c2fe7be3494"><code>af386cf</code></a> Annotate <code>_find_dunder</code> and put measured numbers in the whatsnew</li> <li>Additional commits viewable in <a href="https://github.com/ipython/ipython/compare/9.16.1...9.17.1">compare view</a></li> </ul> </details> <br /> Updates `pytest-randomly` from 4.1.0 to 5.0.0 <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-randomly/blob/main/CHANGELOG.rst">pytest-randomly's changelog</a>.</em></p> <blockquote> <h2>5.0.0 (2026-09-01)</h2> <ul> <li> <p>Support Python 3.15.</p> </li> <li> <p>Shuffle tests in a wrapper around the <code>pytest_collection_modifyitems</code> hook, guaranteeing that the shuffle runs before all other plugins’ implementations of the hook.</p> <p>Previously, pytest-randomly shuffled in a plain <code>tryfirst</code> hook implementation. When another plugin also implemented the hook with <code>tryfirst</code>, as pytest-django does, whichever plugin pytest happened to register later ran first. Registration order comes from package metadata on disk, which can differ between seemingly identical environments — even two containers built from the same <code>Dockerfile</code>, or the same virtual environment after reinstalling a package. As a result, the same seed could yield different test orders in different environments. Worse, in environments where pytest-randomly ended up shuffling last, it silently destroyed the other plugin’s ordering — for pytest-django, the grouping of database tests that mirrors Django’s test runner (non-transactional database tests, then transactional ones, then the rest).</p> <p>Now the shuffle always runs first, and plugins that group tests with a stable sort apply their grouping on top of the shuffled order, so the final order is reproducible from the seed alone. In environments that previously hit the reversed hook order, upgrading changes the test order for a given seed — restoring both reproducibility and other plugins’ grouping.</p> <p><code>PR [#746](pytest-dev/pytest-randomly#746) <https://github.com/pytest-dev/pytest-randomly/pull/746></code><strong>. Thanks to milssky for the report in <code>Issue [#701](pytest-dev/pytest-randomly#701) <https://github.com/pytest-dev/pytest-randomly/issues/701></code></strong>.</p> </li> <li> <p>Require pytest 8+, the first version to require a version of pluggy that supports hook wrappers, as used by the above fix.</p> <p><code>PR [#746](pytest-dev/pytest-randomly#746) <https://github.com/pytest-dev/pytest-randomly/pull/746></code>__.</p> </li> <li> <p>Reset <code>Polyfactory <https://polyfactory.litestar.dev/></code>__\’s default random state at the start of every test, if it is installed.</p> <p>Thanks to Rahul Kumar in <code>PR [#735](pytest-dev/pytest-randomly#735) <https://github.com/pytest-dev/pytest-randomly/issues/735></code>__.</p> </li> <li> <p>Switch package build backend from setuptools to <code>uv_build <https://docs.astral.sh/uv/concepts/build-backend/></code>__. This makes builds with uv about nine times faster, since uv runs the backend natively, without creating a build environment or spawning a Python process. Additionally, source distributions no longer include test files, which setuptools previously included incompletely, missing the files needed to actually run them.</p> </li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/89ddfb1025cf15a81eb3defec7554740f32bcbe3"><code>89ddfb1</code></a> Version 5.0.0</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/0d00951e3fd85145567adfa2b638c7987f3e33ef"><code>0d00951</code></a> Shuffle before other plugins' collection hooks (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/746">#746</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/817091daca7b0540edb45da652ffc84a766724a1"><code>817091d</code></a> Upgrade dependencies (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/745">#745</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/42a2066ee95bdb1c606945436d7170ef3a6376c5"><code>42a2066</code></a> Fix podcast link in README (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/740">#740</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/c2a001d37d14abc95940c923f730a07ccf87b4e2"><code>c2a001d</code></a> Reset Polyfactory's default random state on each test (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/735">#735</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/cc4762bcb547a455b670b812ea362c483a31e7ef"><code>cc4762b</code></a> Upgrade dependencies (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/744">#744</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/94aba4ad675e863b65f024ab924688e595fa8a3f"><code>94aba4a</code></a> Upgrade dependencies (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/743">#743</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/c9140eff32cadcdc14d82a944e63d3ad1b4dbe8c"><code>c9140ef</code></a> Support Python 3.15 (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/741">#741</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/15f531e2a7c1c88f27febc9c92966472d5bb18fc"><code>15f531e</code></a> Switch build backend to uv_build (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/739">#739</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-randomly/commit/79eee6c2f5475911d178b1a42b649182cbfc5e9f"><code>79eee6c</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/pytest-dev/pytest-randomly/issues/738">#738</a>)</li> <li>Additional commits viewable in <a href="https://github.com/pytest-dev/pytest-randomly/compare/4.1.0...5.0.0">compare view</a></li> </ul> </details> <br /> Updates `pytest-rerunfailures` from 16.6 to 16.6.1 <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-rerunfailures/blob/master/CHANGES.rst">pytest-rerunfailures's changelog</a>.</em></p> <blockquote> <h2>16.6.1 (2026-09-03)</h2> <p>Bug Fixes +++++++++</p> <ul> <li>Ensure teardown reports are passed to <code>pytest_runtest_logreport</code> for rerun attempts. (<code>[#237](pytest-dev/pytest-rerunfailures#237) <https://github.com/pytest-dev/pytest-rerunfailures/issues/237></code>_)</li> <li>Prevent superseded built-in subtest failures from remaining in the final test result when rerunning tests with pytest-xdist. (<code>[#350](pytest-dev/pytest-rerunfailures#350) <https://github.com/pytest-dev/pytest-rerunfailures/issues/350></code>_)</li> <li>Restore module, class, and session scoped fixture teardown when a <code>flaky</code> marker condition is falsy. (<code>[#351](pytest-dev/pytest-rerunfailures#351) <https://github.com/pytest-dev/pytest-rerunfailures/issues/351></code>_)</li> <li>Restore module, class, and session scoped fixture teardown when an error raised during teardown rules out a re-run. (<code>[#356](pytest-dev/pytest-rerunfailures#356) <https://github.com/pytest-dev/pytest-rerunfailures/issues/356></code>_)</li> <li>Keep module, class, and session scoped fixtures alive across re-runs of a test whose call phase failed through subtests only. (<code>[#357](pytest-dev/pytest-rerunfailures#357) <https://github.com/pytest-dev/pytest-rerunfailures/issues/357></code>_)</li> <li>Authenticate xdist StatusDB connections with a per-session token. (<code>[#358](pytest-dev/pytest-rerunfailures#358) <https://github.com/pytest-dev/pytest-rerunfailures/issues/358></code>_)</li> <li>Ensure negative rerun counts do not skip the initial test execution. (<code>[#359](pytest-dev/pytest-rerunfailures#359) <https://github.com/pytest-dev/pytest-rerunfailures/issues/359></code>_)</li> </ul> <p>Misc ++++</p> <ul> <li>Replace deprecated <code>Config.getvalue()</code> calls with <code>Config.getoption()</code>. (<code>[#345](pytest-dev/pytest-rerunfailures#345) <https://github.com/pytest-dev/pytest-rerunfailures/issues/345></code>_)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/dad07a7f360e96c0cbbc4301e36cdc439eb9a36b"><code>dad07a7</code></a> Preparing release 16.6.1</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/968fb6c1d3982ea35f041ecb62024e79016324bb"><code>968fb6c</code></a> Prevent negative reruns from skipping initial execution (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/360">#360</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/367df9044cbcf3bbf153269bdab995e1f9eb113c"><code>367df90</code></a> Keep higher-scoped fixtures alive across re-runs of failed subtests (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/357">#357</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/69ac0a7e66f1f55c1e94a2f237e2659250795ef7"><code>69ac0a7</code></a> Authenticate xdist StatusDB connections (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/358">#358</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/20decd37b22736b1a92ecb7a6ed598e7fd70cff1"><code>20decd3</code></a> Restore higher-scoped teardown when a teardown error rules out a re-run (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/356">#356</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/84af73d63c1ac3eeeeba73a5e3ac91a44078c7bb"><code>84af73d</code></a> Fix subtest rerun reporting with xdist (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/352">#352</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/d784cdda0b946c8788939255b6b72df67da82a19"><code>d784cdd</code></a> Test with pytest-xdist on CI (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/354">#354</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/9f85e063dac5387cb0b17ffcb8aadeca545292a8"><code>9f85e06</code></a> Restore higher-scoped teardown when a flaky condition is falsy (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/351">#351</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/eab650fb2a2665d61539aafda81ae549440c2834"><code>eab650f</code></a> Test rerun-except for setup errors (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/349">#349</a>)</li> <li><a href="https://github.com/pytest-dev/pytest-rerunfailures/commit/0b0843a83fb7e79c37e626092a77c5f7cd49f4df"><code>0b0843a</code></a> Fix only_rerun marker precedence test (<a href="https://redirect.github.com/pytest-dev/pytest-rerunfailures/issues/348">#348</a>)</li> <li>Additional commits viewable in <a href="https://github.com/pytest-dev/pytest-rerunfailures/compare/16.6...16.6.1">compare view</a></li> </ul> </details> <br /> Updates `ruff` from 0.16.5 to 0.16.7 <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/astral-sh/ruff/releases">ruff's releases</a>.</em></p> <blockquote> <h2>0.16.7</h2> <h2>Release Notes</h2> <p>Released on 2026-09-10.</p> <h3>Preview features</h3> <ul> <li>[<code>ruff</code>] Add rule for default values on method receivers (<code>RUF077</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/26700">#26700</a>)</li> <li>[<code>ruff</code>] Recognize <code>re.prefixmatch</code> (<code>RUF039</code>, <code>RUF055</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28311">#28311</a>)</li> </ul> <h3>Bug fixes</h3> <ul> <li>Alternate nested quotes inside format spec interpolations (<a href="https://redirect.github.com/astral-sh/ruff/pull/28259">#28259</a>)</li> <li>[<code>flake8-implicit-str-concat</code>] Mark fix unsafe when it creates a docstring (<code>ISC003</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/27981">#27981</a>)</li> <li>[<code>flake8-tidy-imports</code>] Skip fixes for multi-member imports (<code>TID254</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/26584">#26584</a>)</li> <li>[<code>pylint</code>] Gate <code>ImportCycleError</code> on Python 3.15 (<code>PLW0133</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28310">#28310</a>)</li> </ul> <h3>Rule changes</h3> <ul> <li>Correct <code>D211</code> and <code>D203</code> rule conflict diagnostic (<a href="https://redirect.github.com/astral-sh/ruff/pull/28444">#28444</a>)</li> <li>Recognize <code>slice</code> and <code>frozendict</code> generics (<a href="https://redirect.github.com/astral-sh/ruff/pull/28477">#28477</a>)</li> <li>Stop defining <code>__cached__</code> for Python 3.15 (<a href="https://redirect.github.com/astral-sh/ruff/pull/28476">#28476</a>)</li> <li>[<code>pyupgrade</code>] Stop recommending removed <code>typing.no_type_check_decorator</code> (<code>UP035</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28475">#28475</a>)</li> </ul> <h3>Performance</h3> <ul> <li>Reuse parser name lookups when interning (<a href="https://redirect.github.com/astral-sh/ruff/pull/28399">#28399</a>)</li> <li>Speed up inherited configuration resolution (<a href="https://redirect.github.com/astral-sh/ruff/pull/28299">#28299</a>)</li> </ul> <h3>Documentation</h3> <ul> <li>Fix <code>line-length</code> path in <code>--config</code> example (<a href="https://redirect.github.com/astral-sh/ruff/pull/28392">#28392</a>)</li> <li>Remove the "Who’s Using Ruff?" list (<a href="https://redirect.github.com/astral-sh/ruff/pull/28455">#28455</a>)</li> </ul> <h3>Other changes</h3> <ul> <li>Embed archive checksums in the shell installer (<a href="https://redirect.github.com/astral-sh/ruff/pull/28281">#28281</a>)</li> </ul> <h3>Contributors</h3> <ul> <li><a href="https://github.com/The-Compiler"><code>@The-Compiler</code></a></li> <li><a href="https://github.com/mdiniz97"><code>@mdiniz97</code></a></li> <li><a href="https://github.com/zsol"><code>@zsol</code></a></li> <li><a href="https://github.com/gorewilliams"><code>@gorewilliams</code></a></li> <li><a href="https://github.com/RafaelJohn9"><code>@RafaelJohn9</code></a></li> <li><a href="https://github.com/qatcod"><code>@qatcod</code></a></li> <li><a href="https://github.com/zanieb"><code>@zanieb</code></a></li> <li><a href="https://github.com/MichaReiser"><code>@MichaReiser</code></a></li> <li><a href="https://github.com/ntBre"><code>@ntBre</code></a></li> <li><a href="https://github.com/charliermarsh"><code>@charliermarsh</code></a></li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md">ruff's changelog</a>.</em></p> <blockquote> <h2>0.16.7</h2> <p>Released on 2026-09-10.</p> <h3>Preview features</h3> <ul> <li>[<code>ruff</code>] Add rule for default values on method receivers (<code>RUF077</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/26700">#26700</a>)</li> <li>[<code>ruff</code>] Recognize <code>re.prefixmatch</code> (<code>RUF039</code>, <code>RUF055</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28311">#28311</a>)</li> </ul> <h3>Bug fixes</h3> <ul> <li>Alternate nested quotes inside format spec interpolations (<a href="https://redirect.github.com/astral-sh/ruff/pull/28259">#28259</a>)</li> <li>[<code>flake8-implicit-str-concat</code>] Mark fix unsafe when it creates a docstring (<code>ISC003</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/27981">#27981</a>)</li> <li>[<code>flake8-tidy-imports</code>] Skip fixes for multi-member imports (<code>TID254</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/26584">#26584</a>)</li> <li>[<code>pylint</code>] Gate <code>ImportCycleError</code> on Python 3.15 (<code>PLW0133</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28310">#28310</a>)</li> </ul> <h3>Rule changes</h3> <ul> <li>Correct <code>D211</code> and <code>D203</code> rule conflict diagnostic (<a href="https://redirect.github.com/astral-sh/ruff/pull/28444">#28444</a>)</li> <li>Recognize <code>slice</code> and <code>frozendict</code> generics (<a href="https://redirect.github.com/astral-sh/ruff/pull/28477">#28477</a>)</li> <li>Stop defining <code>__cached__</code> for Python 3.15 (<a href="https://redirect.github.com/astral-sh/ruff/pull/28476">#28476</a>)</li> <li>[<code>pyupgrade</code>] Stop recommending removed <code>typing.no_type_check_decorator</code> (<code>UP035</code>) (<a href="https://redirect.github.com/astral-sh/ruff/pull/28475">#28475</a>)</li> </ul> <h3>Performance</h3> <ul> <li>Reuse parser name lookups when interning (<a href="https://redirect.github.com/astral-sh/ruff/pull/28399">#28399</a>)</li> <li>Speed up inherited configuration resolution (<a href="https://redirect.github.com/astral-sh/ruff/pull/28299">#28299</a>)</li> </ul> <h3>Documentation</h3> <ul> <li>Fix <code>line-length</code> path in <code>--config</code> example (<a href="https://redirect.github.com/astral-sh/ruff/pull/28392">#28392</a>)</li> <li>Remove the "Who’s Using Ruff?" list (<a href="https://redirect.github.com/astral-sh/ruff/pull/28455">#28455</a>)</li> </ul> <h3>Other changes</h3> <ul> <li>Embed archive checksums in the shell installer (<a href="https://redirect.github.com/astral-sh/ruff/pull/28281">#28281</a>)</li> </ul> <h3>Contributors</h3> <ul> <li><a href="https://github.com/The-Compiler"><code>@The-Compiler</code></a></li> <li><a href="https://github.com/mdiniz97"><code>@mdiniz97</code></a></li> <li><a href="https://github.com/zsol"><code>@zsol</code></a></li> <li><a href="https://github.com/gorewilliams"><code>@gorewilliams</code></a></li> <li><a href="https://github.com/RafaelJohn9"><code>@RafaelJohn9</code></a></li> <li><a href="https://github.com/qatcod"><code>@qatcod</code></a></li> <li><a href="https://github.com/zanieb"><code>@zanieb</code></a></li> <li><a href="https://github.com/MichaReiser"><code>@MichaReiser</code></a></li> <li><a href="https://github.com/ntBre"><code>@ntBre</code></a></li> <li><a href="https://github.com/charliermarsh"><code>@charliermarsh</code></a></li> <li><a href="https://github.com/nightt5879"><code>@nightt5879</code></a></li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/astral-sh/ruff/commit/b5dba861cc38e3f7fb4524c9ceba3e01a474ea13"><code>b5dba86</code></a> Bump version to 0.16.7 (<a href="https://redirect.github.com/astral-sh/ruff/issues/28496">#28496</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/5992d0504697d86565d8fc3a4d8245a5f4047d24"><code>5992d05</code></a> Install rustfmt before linting releases (<a href="https://redirect.github.com/astral-sh/ruff/issues/28495">#28495</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/1713a1f4325494d883a080d590a25a1946f399e8"><code>1713a1f</code></a> ensure prepare release changes pass prek (<a href="https://redirect.github.com/astral-sh/ruff/issues/28488">#28488</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/18cdbb4f3d14058794420e758864795f55336334"><code>18cdbb4</code></a> use scoped token for release workflow (<a href="https://redirect.github.com/astral-sh/ruff/issues/28484">#28484</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/c3813a501faf887fd01948c98bb8d58ad26488bd"><code>c3813a5</code></a> add a workflow for preparing releases (<a href="https://redirect.github.com/astral-sh/ruff/issues/28486">#28486</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/00948c00a671b81f5358af9f038436bcbb993b38"><code>00948c0</code></a> Remove the "Who’s Using Ruff?" list (<a href="https://redirect.github.com/astral-sh/ruff/issues/28455">#28455</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/86a2eba7b48e3c10386f7ab8a5425c7275d2b427"><code>86a2eba</code></a> [<code>pyupgrade</code>] Stop recommending removed <code>typing.no_type_check_decorator</code> (`UP...</li> <li><a href="https://github.com/astral-sh/ruff/commit/609e184aa35f0034b7ef63e3e04327081c484af6"><code>609e184</code></a> Stop defining <code>__cached__</code> for Python 3.15 (<a href="https://redirect.github.com/astral-sh/ruff/issues/28476">#28476</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/859ff2f01670c43ffff1ea597c8a2e375ada0fbe"><code>859ff2f</code></a> [ty] Track symlinked directory status in listings (<a href="https://redirect.github.com/astral-sh/ruff/issues/28482">#28482</a>)</li> <li><a href="https://github.com/astral-sh/ruff/commit/77f653825800ddaf3bc221ae6db49a500e1002d5"><code>77f6538</code></a> Use paid GitHub-hosted runners for Linux (<a href="https://redirect.github.com/astral-sh/ruff/issues/28478">#28478</a>)</li> <li>Additional commits viewable in <a href="https://github.com/astral-sh/ruff/compare/0.16.5...0.16.7">compare view</a></li> </ul> </details> <br />
Follow-up to #351, the first of the two leaks I mentioned there.
pytest_runtest_teardowntakes the module, class and session finalizers off the setup stack when it expects a re-run. Whether the error a teardown raised is terminal is only worked out afterwards, inpytest_runtest_makereport, so that decision cannot see it. When--rerun-exceptor--only-rerunclassifies that error as one not to re-run on, the protocol then declines to re-run,_restore_suspended_finalizersis never reached, and the fixture's teardown never runs again for the rest of the session:module teardownis not printed. As with #351 the damage is not local, sincesuspended_finalizersis a module-level global: run that file alongside another and the first module's fixture stays un-torn-down past the end of its own module.Adding a term to the gate does not work here, because the error does not exist yet when the gate runs. So the hook becomes a wrapper. On the way in it decides exactly as before. On the way out it looks at the error the teardown phase actually raised, and if that error rules out a re-run it puts the finalizers back and calls
teardown_exact. Running them there rather than just restoring them matters: a restore alone leaves a stale collector on the stack, and the next item'sSetupState.setupasserts on that.If a higher-scoped teardown then fails itself, its error is chained onto the one that got us there instead of replacing it. Replacing it would change what the re-run decision is made on, and the test would start re-running again.
Tests cover class, module and session scope, the cross-module case, and a higher-scoped teardown that fails while being run this way. Two are guards rather than reproductions: an error the filters do allow a re-run on still re-runs and still tears the module fixture down exactly once, and the plain
--rerunspaths are untouched.The remaining leak, premature teardown when a call phase fails through subtests only, is a separate PR.