Skip to content

tests: xdist#8898

Open
mscolnick wants to merge 3 commits intomainfrom
ms/xdist
Open

tests: xdist#8898
mscolnick wants to merge 3 commits intomainfrom
ms/xdist

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

@mscolnick mscolnick commented Mar 27, 2026

This pull request introduces parallel test execution using pytest-xdist across the codebase, improves test reliability with a new fixture, and makes minor improvements to code consistency and determinism. The key changes are grouped below.

Test Parallelization and Workflow Updates:

  • Added pytest-xdist as a test dependency in pyproject.toml to enable parallel test execution.
  • Updated test commands in GitHub Actions workflows (test_be.yaml, test_cli.yaml) to use the -n auto flag, enabling parallel test runs for improved CI speed. [1] [2] [3] [4]
  • Increased the build job timeout in dev_build.yaml to 20 minutes to accommodate potentially longer parallel builds.

Test Reliability and Infrastructure:

  • Added an autouse pytest fixture in tests/conftest.py to ensure __main__.__file__ is set for each worker, preventing failures in tests that rely on this attribute when running with pytest-xdist.

Code Consistency and Determinism:

  • Sorted the order of attributes when dynamically creating test classes in marimo/_ast/pytest.py for consistent test behavior.
  • Ensured deterministic ordering of collected functions in tests/_runtime/test_complete.py by sorting them by module and qualified name.

Copilot AI review requested due to automatic review settings March 27, 2026 15:14
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 27, 2026 5:05pm

Request Review

@mscolnick mscolnick changed the title ms/xdist tests: xdist Mar 27, 2026
@mscolnick mscolnick added the internal A refactor or improvement that is not user facing label Mar 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables running the Python test suite under pytest-xdist (parallel execution) and adds a few determinism fixes to avoid order-dependent failures when tests run concurrently.

Changes:

  • Add pytest-xdist to the test dependency group and enable -n auto in CI workflows.
  • Add a global test fixture intended to ensure __main__.__file__ is set in xdist workers.
  • Make ordering deterministic in a runtime completion test and in marimo’s pytest AST test-class generation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/conftest.py Adds an autouse fixture to patch __main__.__file__ for xdist workers.
tests/_runtime/test_complete.py Sorts collected callables for deterministic parametrization order.
pyproject.toml Adds pytest-xdist to the test dependency group.
marimo/_ast/pytest.py Sorts defs to make generated pytest class attributes deterministic.
.github/workflows/test_cli.yaml Runs CLI tests with pytest -n auto.
.github/workflows/test_be.yaml Runs backend tests with pytest -n auto across dependency matrices.
.github/workflows/dev_build.yaml Adds a job timeout limit.

- CLI tests: use -p no:xdist since they start real servers with port
  binding and have race conditions under parallel execution
- Windows backend: disable xdist due to spawn-based multiprocessing
  causing worker crashes when tests modify __main__
- Improve _ensure_main_has_file fixture: use shutil.which for robust
  path resolution, properly restore original state in cleanup
Copy link
Copy Markdown
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

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

Nice. Can you leave a comment documenting the issue on Windows, with a TODO to fix it?

These are the tests I saw that failed.

FAILED tests/_islands/test_island_generator.py::test_build - worker 'gw1' crashed while running 'tests/_islands/test_island_generator.py::test_build'
FAILED tests/_messaging/test_streams.py::test_import_multiprocessing - worker 'gw0' crashed while running 'tests/_messaging/test_streams.py::test_import_multiprocessing'
FAILED tests/_server/api/endpoints/test_ai.py::TestOpenAiEndpoints::test_completion_without_token - worker 'gw2' crashed while running 'tests/_server/api/endpoints/test_ai.py::TestOpenAiEndpoints::test_completion_without_token'
FAILED tests/_server/test_session_manager.py::test_create_session_new - worker 'gw4' crashed while running 'tests/_server/test_session_manager.py::test_create_session_new'
FAILED tests/_islands/test_island_generator.py::test_render - worker 'gw5' crashed while running 'tests/_islands/test_island_generator.py::test_render'
FAILED tests/_server/test_session_manager.py::test_create_session_absolute_url - worker 'gw6' crashed while running 'tests/_server/test_session_manager.py::test_create_session_absolute_url'
FAILED tests/_islands/test_island_generator.py::test_render_multiline_markdown - worker 'gw7' crashed while running 'tests/_islands/test_island_generator.py::test_render_multiline_markdown'
FAILED tests/_server/test_session_manager.py::test_create_session_with_script_config_overrides - worker 'gw8' crashed while running 'tests/_server/test_session_manager.py::test_create_session_with_script_config_overrides'
FAILED tests/_server/test_session_manager.py::test_recents_touch_called_on_session_create - worker 'gw9' crashed while running 'tests/_server/test_session_manager.py::test_recents_touch_called_on_session_create'

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

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants