Skip to content

Let worker/controller helpers accept a Config and tolerate disabled xdist - #1398

Open
RonnyPfannschmidt wants to merge 2 commits into
masterfrom
claude/xdist-1397-y3cbkv
Open

RonnyPfannschmidt wants to merge 2 commits into
masterfrom
claude/xdist-1397-y3cbkv

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Oct 11, 2026 •

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 #1397. Follows the approach @MaciejZiel proposed in the issue.

Before: is_xdist_worker, is_xdist_controller and get_xdist_worker_id only accepted a request or session, so passing config from pytest_configure / pytest_terminal_summary raised AttributeError. With -p no:xdist, is_xdist_controller(session) raised because config.option.dist does not exist.

After: all three accept a pytest.Config too, and is_xdist_controller returns False when the dist option is missing.

How: a small _get_config() helper returns obj.config when present, else the object itself (duck-typed, so existing fake request objects keep working). is_xdist_controller reads dist with a "no" default. Its docstring now notes that the result is only reliable from pytest_configure on: earlier hooks (e.g. another plugin's tryfirst pytest_cmdline_main) run before xdist turns -n into a dist mode and get False. Docs gain a short example for config-only hooks and a note that has_plugin("dsession") is not reliable before pytest_sessionstart.

  • Tests: TestAPI::test_helpers_accept_config runs a conftest with -n2, -n0, no -n, and -p no:xdist, checking pytest_configure, pytest_sessionstart and pytest_terminal_summary; it fails on master and passes here.
  • Changelog: changelog/1397.feature.rst.

…dist

is_xdist_worker, is_xdist_controller and get_xdist_worker_id now accept
a pytest.Config in addition to a request or session, so plugins can use
them from config-only hooks like pytest_configure. is_xdist_controller
returns False instead of raising when xdist is disabled with -p no:xdist.

Fixes #1397

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gif5hXSqzpuBiMBEFT8j9
…ure on

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gif5hXSqzpuBiMBEFT8j9
@RonnyPfannschmidt
RonnyPfannschmidt marked this pull request as ready for review October 19, 2026 21:47

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.

is_xdist_controller() can't be used from config-only hooks and raises when xdist is disabled

2 participants