Skip to content

Fix missing results for tests marked with xdist_group - #26293

Open
Usama (PSEUDO) (pseudo-usama) wants to merge 1 commit into
microsoft:mainfrom
pseudo-usama:fix-xdist-group-test-results
Open

Usama (PSEUDO) (pseudo-usama) wants to merge 1 commit into
microsoft:mainfrom
pseudo-usama:fix-xdist-group-test-results

Conversation

@pseudo-usama

Copy link
Copy Markdown

Fixes #24935

With --dist=loadgroup, pytest-xdist renames every test marked with @pytest.mark.xdist_group to <test id>@<group> on its workers, so that its scheduler can keep a group on one worker. The pytest plugin sent results under these renamed ids. Discovery runs without xdist, so the ids didn't match any test item and the Test Explorer showed no result for grouped tests, while ungrouped tests in the same run were fine.

The plugin now removes the group suffix before building the id it sends back. It does this only for tests that have the xdist_group marker, and only strips an @ that comes after the parametrize id (the same way pytest-xdist reads the group name back), so ids like test_email[user@example.com] keep their @.

Testing

  • New test_xdist_group_execution runs a file with grouped passing, failing, skipped and parametrized tests (one parameter id contains @) under -n 1 --dist=loadgroup and checks the result ids. It fails on main with ...::test_grouped@group_a ids and passes with this change. It's skipped on Windows because the test harness's named pipe accepts a single connection, and the xdist controller and worker both connect to it.
  • New unit tests for remove_xdist_group_suffix.
  • Added pytest-xdist to build/test-requirements.txt so that CI runs the new test.
  • python python_files/tests/run_all.py: 233 passed, 2 skipped (macOS, Python 3.12, with pytest 8.4.2 and 9.2.0).
  • ruff check, ruff format --check and pyright 1.1.308 report nothing new.
  • Also checked by hand that class-level and module-level (pytestmark) xdist_group markers give clean ids, and that the ids sent during execution match the runIDs that discovery returns for the same file.

Note for reviewers: under xdist the controller process also re-sends every result with a <cwd>::<name> id, for all xdist runs, grouped or not. Those ids match no test, so the extension ignores them. I left that alone to keep this PR focused; the new test only compares the results sent with the file path.

Suggested label: bug

With --dist=loadgroup, pytest-xdist renames tests marked with
xdist_group to "<test id>@<group>" on its workers. The pytest plugin
sent results under these renamed ids, which don't match the ids found
during discovery, so the Test Explorer showed no result for them.

Remove the group suffix before building the test id that is sent back.

Fixes microsoft#24935
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.

Test Explorer is not reporting test status if a test is annotated with xdist_group

1 participant