fix(tests): isolate test_project_dependencies from pyproject.toml pollution#9634
Merged
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
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)
Contributor
There was a problem hiding this comment.
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.tomlcontents attests/conftest.pyimport time and expose them via a session-scopedpyproject_textfixture. - Update
tests/test_project_dependencies.pyto parse dependencies from thepyproject_textfixture 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. |
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.7-dev70 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was authored by a coding agent.
Fixes marimo-team/ci-agent#27.
test_required_dependenciesreads the live on-diskpyproject.toml. Under pytest-xdist, a leaking realuv addfrom a parallel test can appendtest-packagemid-session (theuv syncstep fails without rolling back the file write), flaking the snapshot read.Cache
pyproject.tomlcontents attests/conftest.pyimport time (worker startup, before any test runs) and expose them via a session-scopedpyproject_textfixture.Test plan
uv run --group test pytest tests/test_project_dependencies.py -vuv run --group test pytest tests/test_project_dependencies.py tests/_runtime/packages/ tests/_server/api/endpoints/test_packages.py -n auto