A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
tests: xdist (#8898)
Myles Scolnickd7a625b9821c
diff --git a/.github/workflows/dev_build.yaml b/.github/workflows/dev_build.yamlindex 4e743bbee4..59f5c66075 100644--- a/.github/workflows/dev_build.yaml+++ b/.github/workflows/dev_build.yaml@@ -11,6 +11,7 @@ permissions:jobs:build:+ timeout-minutes: 20strategy:matrix:os: [ubuntu-latest, macos-latest]diff --git a/.github/workflows/test_be.yaml b/.github/workflows/test_be.yamlindex 9e8987a62b..3646fec286 100644--- a/.github/workflows/test_be.yaml+++ b/.github/workflows/test_be.yaml@@ -186,11 +186,24 @@ jobs:# Test with base dependencies# Exit code 5 = no tests collected (e.g. only CLI test files changed);# treat that as success since CLI tests run in a separate workflow.+ #+ # TODO: xdist is disabled on Windows because several tests+ # crash workers. Fix and re-enable. Failing tests:+ # - tests/_islands/test_island_generator.py::test_build+ # - tests/_islands/test_island_generator.py::test_render+ # - tests/_islands/test_island_generator.py::test_render_multiline_markdown+ # - tests/_messaging/test_streams.py::test_import_multiprocessing+ # - tests/_server/api/endpoints/test_ai.py::TestOpenAiEndpoints::test_completion_without_token+ # - tests/_server/test_session_manager.py::test_create_session_new+ # - tests/_server/test_session_manager.py::test_create_session_absolute_url+ # - tests/_server/test_session_manager.py::test_create_session_with_script_config_overrides+ # - tests/_server/test_session_manager.py::test_recents_touch_called_on_session_create- name: Test changed with base dependenciesif: ${{ matrix.dependencies == 'core' }}run: |uv run --python ${{ matrix.python-version }} --group test pytest tests/ \-v \+ ${{ matrix.os != 'windows-latest' && '-n auto' || '-p no:xdist' }} \-k "not test_cli" \--durations=10 \-p packages.pytest_changed \@@ -205,6 +218,7 @@ jobs:run: |uv run --python ${{ matrix.python-version }} --group test-optional pytest tests/ \-v \+ ${{ matrix.os != 'windows-latest' && '-n auto' || '-p no:xdist' }} \-k "not test_cli" \--durations=10 \-p packages.pytest_changed \@@ -221,6 +235,7 @@ jobs:run: |uv run --python ${{ matrix.python-version }} --group test pytest tests/ \-v \+ ${{ matrix.os != 'windows-latest' && '-n auto' || '-p no:xdist' }} \-k "not test_cli" \--durations=10 \-p packages.pytest_changed \diff --git a/.github/workflows/test_cli.yaml b/.github/workflows/test_cli.yamlindex 7516544ebd..584ca5f82f 100644--- a/.github/workflows/test_cli.yaml+++ b/.github/workflows/test_cli.yaml@@ -148,12 +148,15 @@ jobs:with:name: testwheel+ # xdist is disabled for CLI tests because they test process-level+ # behavior (spawning marimo processes, port binding) that conflicts+ # with parallel execution.- name: Test CLIshell: bashrun: |uv venvuv pip install --group=test-optional --group=dev marimo*.whl- uv run --no-project pytest -v tests/_cli/test_cli* --maxfail=2+ uv run --no-project pytest -v tests/_cli/test_cli* -p no:xdist --maxfail=2test_examples:needs: [changes]diff --git a/marimo/_ast/pytest.py b/marimo/_ast/pytest.pyindex e8ee5d8e65..78a1d8fbb9 100644--- a/marimo/_ast/pytest.py+++ b/marimo/_ast/pytest.py@@ -417,7 +417,7 @@ def build_test_class("marimo-team/marimo/issues.")- attrs = {var: h for var in defs if (h := hook(var)) is not None}+ attrs = {var: h for var in sorted(defs) if (h := hook(var)) is not None}return type(name, (MarimoTest,), attrs)diff --git a/pyproject.toml b/pyproject.tomlindex d90dc62f5c..b04dac626d 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -146,6 +146,7 @@ test = ["pytest-asyncio~=1.3.0","pytest-picked>=0.5.1","pytest-sugar~=1.1.1",+ "pytest-xdist~=3.5",# Comparison testing"inline-snapshot~=0.29.0","hypothesis~=6.102.1",diff --git a/tests/_runtime/test_complete.py b/tests/_runtime/test_complete.pyindex 51c96a072f..7c1aaf94d7 100644--- a/tests/_runtime/test_complete.py+++ b/tests/_runtime/test_complete.py@@ -313,7 +313,10 @@ def collect_functions_to_check():continueobjects_to_check.add(obj)assert len(objects_to_check) > 1- return objects_to_check+ return sorted(+ objects_to_check,+ key=lambda obj: f"{obj.__module__}.{obj.__qualname__}",+ )def dummy_func(arg1: str, arg2: str) -> None:diff --git a/tests/conftest.py b/tests/conftest.pyindex 14b6bb460c..bfe423515b 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -86,6 +86,46 @@ def pytest_collection_modifyitems(item.add_marker(pytest.mark.skip(reason=reason))[email protected](autouse=True)+def _ensure_main_has_file() -> Generator[None, None, None]:+ """Ensure __main__.__file__ is set for pytest-xdist workers.++ xdist workers don't always set __file__ on __main__, which causes+ marimo's kernel (create_main_module) to set __file__=None, breaking+ tests that rely on __file__ being a real path.+ """+ main = sys.modules.get("__main__")+ if main is None:+ yield+ return++ had_file_attr = hasattr(main, "__file__")+ original_file = getattr(main, "__file__", None)++ if not had_file_attr or original_file is None:+ # Find a valid pytest path: prefer shutil.which, fall back to+ # sys.argv[0], then construct one from sys.executable.+ pytest_path = shutil.which("pytest")+ if pytest_path and Path(pytest_path).exists():+ new_file = pytest_path+ elif sys.argv and sys.argv[0] and Path(sys.argv[0]).exists():+ new_file = sys.argv[0]+ else:+ new_file = str(Path(sys.executable).parent / "pytest")+ main.__file__ = new_file++ try:+ yield+ finally:+ current_main = sys.modules.get("__main__")+ if current_main is not None:+ if had_file_attr:+ # Restore the original value (which may be None)+ current_main.__file__ = original_file+ elif hasattr(current_main, "__file__"):+ del current_main.__file__++@pytest.fixture(autouse=True)def patch_random_seed(monkeypatch: pytest.MonkeyPatch) -> None:"""Patch UIElement._random_seed to use a fixed seed for testing"""