Skip to content

Add --max-module-reruns and --max-class-reruns scope caps - #381

Open
LouisDeconinck wants to merge 2 commits into
pytest-dev:masterfrom
LouisDeconinck:issue-213-scope-rerun-limits
Open

LouisDeconinck wants to merge 2 commits into
pytest-dev:masterfrom
LouisDeconinck:issue-213-scope-rerun-limits

Conversation

@LouisDeconinck

@LouisDeconinck LouisDeconinck commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds --max-module-reruns N and --max-class-reruns N, capping the total number of reruns within each module / test class — extending the existing suite-wide --max-suite-reruns mechanism to the scopes requested in the issue
  • Scope counters live in StatusDB (in-memory) and are shared through the socket StatusDB under pytest-xdist, so caps hold for parallel runs; slots are reserved atomically alongside the suite slot and released if a later scope is exhausted
  • The teardown-time finalizer suspension check now uses the same combined cap check, so scope exhaustion doesn't leak suspended finalizers

Closes #213

Test plan

  • Per-module cap limits reruns in one module but not others
  • Per-class cap limits reruns in one class but not others; function tests unaffected by --max-class-reruns
  • Negative values rejected; existing --max-suite-reruns tests still pass; full suite green

Extend the suite-wide rerun budget to per-module and per-class scopes:
counters are kept in StatusDB (in-memory, or the shared socket DB under
xdist) and reserved alongside the suite slot when a rerun is scheduled, so
the caps hold for parallel runs too.

Closes pytest-dev#213.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The class-scope key is derived with item.nodeid.rpartition('::')[0], but parametrized IDs may themselves contain ::. For example, test.py::TestC::test_x[a::b] produces a key ending in test_x[a, rather than the class node ID, so different parameter IDs can get separate counters and exceed --max-class-reruns. Could this derive the scope from the structured parent/class node instead of splitting the nodeid string, and add a parameter ID containing :: as a regression?

Splitting the item nodeid on '::' broke when a parametrized ID itself
contained '::', giving each parameter its own class-scope counter.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@LouisDeconinck

Copy link
Copy Markdown
Contributor Author

Fixed in 2866443: module/class scope keys are now derived from item.listchain() (pytest.Module/pytest.Class nodeids) instead of splitting the nodeid, so parametrized IDs containing :: share one counter. Added a regression test with a::b-style param IDs.

@LouisDeconinck

Copy link
Copy Markdown
Contributor Author

Fixed — class/module scopes are now derived from the node hierarchy instead of splitting the nodeid, so parameter IDs containing :: get a single counter, with a regression test for test_x[a::b] (2866443).

sylvesterkaczmarek

This comment was marked as duplicate.

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.

Limit reruns per scope (module, class)

2 participants