Skip to content

Parse loadscope scopes with pytest's nodeid grammar - #1413

Open
RonnyPfannschmidt wants to merge 2 commits into
masterfrom
claude/project-thread-vgqh68
Open

RonnyPfannschmidt wants to merge 2 commits into
masterfrom
claude/project-thread-vgqh68

Conversation

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Requested by Ronny · project thread

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest-xdist maintainers; I prompted it, it did the work, I read it.

Fixes #1335. Supersedes #1350 and #1382; both authors are credited as co-authors and their test cases are reused.

LoadScopeScheduling._split_scope used nodeid.rsplit("::", 1), so a :: inside a parametrization id (IPv6 addresses, for example) split one module or class into several work units.

This PR parses the nodeid the way pytest's own NodeId.parse does (pytest-dev/pytest#14758). The first :: ends the path, and the first [ after it starts the parametrization id. The scope is the path plus every name except the last.

Compared with the two earlier PRs:

All of these cases are covered by TestLoadScope::test_split_scope. There is also an acceptance test with :: ids under -n2 --dist=loadscope. Both fail on master and pass with this change.

  • Tests added
  • Changelog fragment changelog/1335.bugfix.rst

Local runs: full testing/ suite passes on pytest 9.1.1. On pytest main, the only failure is test_remote_usage_prog, which also fails on master; it comes from an untagged local pytest checkout. pre-commit is clean on the changed files.


Generated by Claude Code

`LoadScopeScheduling._split_scope` used `nodeid.rsplit("::", 1)`, so a
`::` inside a parametrization id (e.g. IPv6 addresses) split a module or
class into several work units.

Parse the nodeid the way pytest does: the first `::` ends the path, the
first `[` after it starts the parametrization id, and the scope is the
path plus all names but the last. This also handles non-.py items,
unbalanced brackets in ids and `[` in paths.

Fixes #1335. Supersedes #1350 and #1382; their test cases are reused.

Co-authored-by: itscloud0 <89895960+itscloud0@users.noreply.github.com>
Co-authored-by: Louis Deconinck <27673665+LouisDeconinck@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014GZsREv63hfLhYEKWU14vE

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the loadscope scope-parsing fix.

No open issues 🎉

What changed in this PR

Fixes #1335 by making loadscope scope parsing follow pytest’s nodeid grammar, keeping tests grouped by module or class when parameter IDs contain ::.

Changes:

  • Separates the path and test names before ignoring parametrization content.
  • Adds parser regressions for bracket and separator edge cases, plus a two-worker grouping acceptance test.
  • Documents the fix in a changelog fragment.
File Description
testing/​acceptance_test.py Adds scope-parsing cases and verifies module grouping with :: parameter IDs.
src/​xdist/​scheduler/​loadscope.py Updates scope parsing and its documentation to follow pytest’s nodeid grammar.
changelog/​1335.bugfix.rst Records the loadscope grouping fix.

Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014GZsRFm6asVUgAJ3erG6Nu

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadscope bug: :: in test parameters breaks scope detection

3 participants