From 3422034f7d8ed9b77875f4adab27b765c1fa9dab Mon Sep 17 00:00:00 2001 From: misrasaurabh1 Date: Sat, 31 Jan 2026 00:14:38 -0800 Subject: [PATCH 1/4] pytest-xdist in ci --- .github/workflows/unit-tests.yaml | 4 ++-- .github/workflows/windows-unit-tests.yml | 4 ++-- pyproject.toml | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 88130cd03..d9a0a66ce 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -30,11 +30,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: install dependencies - run: uv sync + run: uv sync --group ci - name: Install test-only dependencies (Python 3.9 and 3.13) if: matrix.python-version == '3.9' || matrix.python-version == '3.13' run: uv sync --group tests - name: Unit tests - run: uv run pytest tests/ + run: uv run pytest tests/ -n auto diff --git a/.github/workflows/windows-unit-tests.yml b/.github/workflows/windows-unit-tests.yml index 20b2da52e..d37caba47 100644 --- a/.github/workflows/windows-unit-tests.yml +++ b/.github/workflows/windows-unit-tests.yml @@ -28,7 +28,7 @@ jobs: python-version: "3.13" - name: install dependencies - run: uv sync + run: uv sync --group ci - name: Unit tests - run: uv run pytest tests/ + run: uv run pytest tests/ -n auto diff --git a/pyproject.toml b/pyproject.toml index 82e4f21a6..daf6d3ab8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,6 +81,9 @@ dev = [ "uv>=0.6.2", "pre-commit>=4.2.0,<5", ] +ci = [ + "pytest-xdist>=3.5.0", +] tests = [ "black>=25.9.0", "jax>=0.4.30", From 57a0e850d399f423ea2e4d7765f3bc19cea0b24c Mon Sep 17 00:00:00 2001 From: misrasaurabh1 Date: Sat, 31 Jan 2026 00:27:02 -0800 Subject: [PATCH 2/4] pytest-xdist in ci --- .github/workflows/unit-tests.yaml | 2 +- tests/conftest.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index d9a0a66ce..f44beac85 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -34,7 +34,7 @@ jobs: - name: Install test-only dependencies (Python 3.9 and 3.13) if: matrix.python-version == '3.9' || matrix.python-version == '3.13' - run: uv sync --group tests + run: uv sync --group ci --group tests - name: Unit tests run: uv run pytest tests/ -n auto diff --git a/tests/conftest.py b/tests/conftest.py index 40578cf33..64423640c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,6 +4,23 @@ from codeflash.languages import reset_current_language +# Test modules that modify files in code_to_optimize/ must run in the same xdist worker +# to avoid race conditions when running tests in parallel +SHARED_FILE_TEST_MODULES = { + "test_comparator", + "test_instrumentation_run_results_aiservice", + "test_instrument_all_and_run", + "test_async_run_and_parse_tests", +} + + +def pytest_collection_modifyitems(items): + """Mark tests that modify shared files to run in the same xdist worker.""" + for item in items: + module_name = item.module.__name__.split(".")[-1] + if module_name in SHARED_FILE_TEST_MODULES: + item.add_marker(pytest.mark.xdist_group("code_to_optimize_files")) + @pytest.fixture(autouse=True) def set_python_language(): From 7e7783ce571a6a9cfcb27ad6e090436ae967bd43 Mon Sep 17 00:00:00 2001 From: misrasaurabh1 Date: Sat, 31 Jan 2026 00:39:26 -0800 Subject: [PATCH 3/4] fix load dist --- .github/workflows/unit-tests.yaml | 2 +- tests/conftest.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index f44beac85..dc444a818 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -37,4 +37,4 @@ jobs: run: uv sync --group ci --group tests - name: Unit tests - run: uv run pytest tests/ -n auto + run: uv run pytest tests/ -n auto --dist loadgroup diff --git a/tests/conftest.py b/tests/conftest.py index 64423640c..a966bd948 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ "test_instrumentation_run_results_aiservice", "test_instrument_all_and_run", "test_async_run_and_parse_tests", + "test_instrument_tests", } From 1543001aca6ba1f9c2ee10613e6702038541aaa0 Mon Sep 17 00:00:00 2001 From: misrasaurabh1 Date: Sat, 31 Jan 2026 00:45:25 -0800 Subject: [PATCH 4/4] fix load dist --- .github/workflows/unit-tests.yaml | 2 +- .github/workflows/windows-unit-tests.yml | 2 +- tests/conftest.py | 18 ------------------ 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index dc444a818..6511b37cc 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -37,4 +37,4 @@ jobs: run: uv sync --group ci --group tests - name: Unit tests - run: uv run pytest tests/ -n auto --dist loadgroup + run: uv run pytest tests/ -n auto --dist loadfile diff --git a/.github/workflows/windows-unit-tests.yml b/.github/workflows/windows-unit-tests.yml index d37caba47..f16d7871a 100644 --- a/.github/workflows/windows-unit-tests.yml +++ b/.github/workflows/windows-unit-tests.yml @@ -31,4 +31,4 @@ jobs: run: uv sync --group ci - name: Unit tests - run: uv run pytest tests/ -n auto + run: uv run pytest tests/ -n auto --dist loadfile diff --git a/tests/conftest.py b/tests/conftest.py index a966bd948..40578cf33 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,24 +4,6 @@ from codeflash.languages import reset_current_language -# Test modules that modify files in code_to_optimize/ must run in the same xdist worker -# to avoid race conditions when running tests in parallel -SHARED_FILE_TEST_MODULES = { - "test_comparator", - "test_instrumentation_run_results_aiservice", - "test_instrument_all_and_run", - "test_async_run_and_parse_tests", - "test_instrument_tests", -} - - -def pytest_collection_modifyitems(items): - """Mark tests that modify shared files to run in the same xdist worker.""" - for item in items: - module_name = item.module.__name__.split(".")[-1] - if module_name in SHARED_FILE_TEST_MODULES: - item.add_marker(pytest.mark.xdist_group("code_to_optimize_files")) - @pytest.fixture(autouse=True) def set_python_language():