Skip to content

ci(tests): Let filtered pytest-selected runs opt into the per-file plan - #133153

Merged
joshuarli merged 2 commits into
masterfrom
ci/pytest-selected-marker-file-sharding
Dec 2, 2026
Merged

joshuarli merged 2 commits into
masterfrom
ci/pytest-selected-marker-file-sharding

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Snuba's CI runs Sentry's tests filtered with -m 'snuba_ci or snuba' (or -m snuba_ci) and -k 'not __In'. When -m/-k is present, pytest-selected.py skips the per-file plan, so every shard, and every xdist worker in it, collects the whole Sentry suite before keeping its hash share. In Snuba's API-change runs that collection takes about 6–7 minutes of every shard, and adding shards doesn't shrink it.

The fallback exists because a filter can leave some shards with no selected tests. This adds an opt-in, PYTEST_SELECTED_FILTERED_PLAN=1, for callers that accept that:

  • Filtered full runs use the same plan_full_shards plan as unfiltered ones. Every candidate file still goes to a shard, including files missing from the durations, so no file is dropped. Pytest then applies -m/-k to the files it collects, so marker inheritance, parametrization, and hook-added markers behave as before.
  • A filtered shard whose files have no selected tests exits 0 instead of 5. Unfiltered shards with no tests still fail.
  • Without the variable, filtered runs keep today's behavior.

Snuba turns this on in getsentry/snuba#8772.

Known limit: balancing still uses the full backend durations, so a filtered run's selected tests can spread unevenly across shards. Snuba-specific weights are a follow-up only if the measured slowest shard shows it.

via @joshuarli.

--

View Session [Sentry]

Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 2, 2026
Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@sentry-junior
sentry-junior Bot requested a review from joshuarli December 2, 2026 01:41
@joshuarli
joshuarli marked this pull request as ready for review December 2, 2026 01:43
@joshuarli
joshuarli requested a review from a team as a code owner December 2, 2026 01:43
@joshuarli
joshuarli merged commit 5799664 into master Dec 2, 2026
77 checks passed
@joshuarli
joshuarli deleted the ci/pytest-selected-marker-file-sharding branch December 2, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant