Skip to content

fix(tests): isolate test_project_dependencies from pyproject.toml pollution#9634

Merged
mscolnick merged 1 commit into
mainfrom
ms/fix/flakey-ci-agent-issues
May 21, 2026
Merged

fix(tests): isolate test_project_dependencies from pyproject.toml pollution#9634
mscolnick merged 1 commit into
mainfrom
ms/fix/flakey-ci-agent-issues

Conversation

@mscolnick

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

Fixes marimo-team/ci-agent#27.

test_required_dependencies reads the live on-disk pyproject.toml. Under pytest-xdist, a leaking real uv add from a parallel test can append test-package mid-session (the uv sync step fails without rolling back the file write), flaking the snapshot read.

Cache pyproject.toml contents at tests/conftest.py import time (worker startup, before any test runs) and expose them via a session-scoped pyproject_text fixture.

Test plan

  • uv run --group test pytest tests/test_project_dependencies.py -v
  • uv run --group test pytest tests/test_project_dependencies.py tests/_runtime/packages/ tests/_server/api/endpoints/test_packages.py -n auto
…lution

`test_required_dependencies` snapshot-compared the live on-disk
`pyproject.toml`. Under pytest-xdist, a leaking real `uv add` from a
parallel test can append a bare `test-package` line mid-session (the
`uv sync` step may fail without rolling back the file write), which
then flakes the snapshot read on whatever worker happens to run the
dependency test.

Cache the file's contents at conftest import time (i.e. at worker
startup, before any test runs on any worker) and expose a session
fixture so the snapshot tests are immune to on-disk mutations.
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 21, 2026 12:24am

Request Review

@mscolnick mscolnick added the bug Something isn't working label May 21, 2026
@mscolnick mscolnick marked this pull request as ready for review May 21, 2026 00:25
@mscolnick mscolnick requested review from Copilot and manzt May 21, 2026 00:25

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Architecture diagram
sequenceDiagram
    participant Pytest as Pytest Worker (xdist)
    participant conftest as conftest.py (import time)
    participant Pyproject as pyproject.toml (on disk)
    participant Fixture as pyproject_text fixture (session-scoped)
    participant Test as test_required_dependencies
    participant Tomlkit as tomlkit library
    participant Snapshot as snapshotter

    Note over Pytest,Snapshot: Worker startup (worker 0..N)
    
    Pytest->>conftest: Import conftest.py
    conftest->>Pyproject: Read pyproject.toml content
    Pyproject-->>conftest: Raw text
    conftest->>conftest: Cache text as _PYPROJECT_TEXT_AT_SESSION_START

    Note over Pytest,Snapshot: Mid-session: parallel test mutates pyproject.toml
    Pytest->>Pyproject: Leaking uv add writes to pyproject.toml
    Pyproject-->>Pytest: File mutated (on disk)

    Note over Pytest,Snapshot: test_required_dependencies execution
    Pytest->>Test: Run test (any worker)
    Test->>Fixture: Request pyproject_text fixture
    Fixture->>conftest: Retrieve cached _PYPROJECT_TEXT_AT_SESSION_START
    conftest-->>Fixture: Cached text (immune to mid-session mutations)
    Fixture-->>Test: pyproject_text string
    Test->>Tomlkit: tomlkit.loads(pyproject_text)
    Tomlkit-->>Test: Parsed pyproject dict
    Test->>Test: Extract and sort dependencies
    Test->>Snapshot: Snapshot dependency list
    Snapshot-->>Test: Snapshot comparison complete
    Test-->>Pytest: Test result (pass/fail)
Loading

Re-trigger cubic

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes flaky dependency snapshot tests under pytest-xdist by preventing mid-session pyproject.toml mutations (e.g., from a leaking uv add) from affecting tests/test_project_dependencies.py reads.

Changes:

  • Cache pyproject.toml contents at tests/conftest.py import time and expose them via a session-scoped pyproject_text fixture.
  • Update tests/test_project_dependencies.py to parse dependencies from the pyproject_text fixture instead of reading from disk during the test.

Reviewed changes

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

File Description
tests/conftest.py Adds a session-scoped pyproject_text fixture backed by import-time cached pyproject.toml contents to avoid xdist-induced flakiness.
tests/test_project_dependencies.py Switches dependency snapshot tests to use the cached pyproject_text fixture rather than reading pyproject.toml directly.
@mscolnick mscolnick merged commit cd40f73 into main May 21, 2026
40 of 45 checks passed
@mscolnick mscolnick deleted the ms/fix/flakey-ci-agent-issues branch May 21, 2026 13:04
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.7-dev70

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

Labels

bug Something isn't working

2 participants