Skip to content

Backend CI: pin pytest below 9.2 - #15624

Merged
danielhanchen merged 1 commit into
mainfrom
ci-pin-pytest-below-9-2
Oct 28, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-pin-pytest-below-9-2

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Backend CI / Repo tests (CPU, rest) and the (Python 3.13, a-f) / (g-r) shards started failing on every PR with 55 to 70 errors such as AttributeError: torch._dynamo.config.suppress_errors does not exist, torch._dynamo.config.recompile_limit does not exist, torch._inductor.config ... has no attribute 'post_grad_custom_post_pass' and torch.compiler.config ... has no attribute 'cache_key_tag'. No commit on main caused it: the only difference between the installed packages of the last green main run (job 122393302946, main at c4f9de9) and the first red one (job 122418439854) is pytest-9.1.1 -> pytest-9.2.0.

Cause

pytest 9.2.0 changed how monkeypatch.setattr records the old value: it now reads it from the target's instance __dict__ whenever the class has no data descriptor for the name. torch's ConfigModule (torch._dynamo.config, torch._inductor.config, torch.compiler.config) keeps its values in _config, not in __dict__, so pytest records the old value as missing and on teardown calls delattr(config, name). ConfigModule.__delattr__ removes the key, so every later read in that xdist worker raises ... does not exist, and the next monkeypatch.setattr on it fails with has no attribute.

Minimal reproduction (one test patches torch._dynamo.config.suppress_errors with monkeypatch.setattr, the next reads it):

pytest result
9.1.1 2 passed
9.2.0 1 failed: AttributeError: torch._dynamo.config.suppress_errors does not exist

Change

.github/workflows/studio-backend-ci.yml: both backend test installs now use 'pytest<9.2' (they were unpinned). The Core CPU setup action already pins pytest==9.0.3 and is unaffected. Once pytest handles ConfigModule again, the pin can be lifted.

@danielhanchen danielhanchen self-assigned this Oct 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T23:56:56.062731Z a34dbe9 Manual request
🔒 Security Review ✅ Completed 2026-10-27T23:58:10.363526Z a34dbe9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: a34dbe9e92

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen

Copy link
Copy Markdown
Member Author

One more consequence of pytest 9.2.0 that this pin also fixes: pytest-xdist 3.8.0 (still the latest) tags an xdist_group test by rewriting item._nodeid, and pytest 9.2 now builds nodeid from a structured _id, so --dist loadgroup stops grouping anything. That is what has been failing test_mcp_session_cache_reset_between_tests.py on the g-r shard (#15587, #15593, #15601, #15615): the two tests of the pair landed on gw0 and gw3. Locally, studio/backend/tests/test_mcp_*.py -n 4 --dist loadgroup fails that pair on every 9.2.0 run and passes on 9.1.1. #15638 adds a check that fails grouped tests by name if loadgroup stops tagging them, plus the same pin for the version-compat lanes.

@danielhanchen

Copy link
Copy Markdown
Member Author

The Repo tests (CPU, rest) run on this head confirms the pin: pytest 9.1.1 was installed and none of the torch._dynamo.config ... does not exist errors appear (15161 passed). The one failure, tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[11], is the video.py read that #15623 already fixed on main; this run's base (71dd6d2) predates it, so merging main clears it.

@danielhanchen
danielhanchen merged commit a6c7885 into main Oct 28, 2026
22 of 23 checks passed
@danielhanchen
danielhanchen deleted the ci-pin-pytest-below-9-2 branch October 28, 2026 03:54
danielhanchen added a commit that referenced this pull request Oct 28, 2026
…g (pytest 9.2) (#15638)

## Summary


`studio/backend/tests/test_mcp_session_cache_reset_between_tests.py::test_the_next_test_starts_with_an_empty_cache_and_the_session_closed`
has failed on the `(Python 3.13, g-r)` shard of #15587, #15593, #15601
and #15615 (`assert 0 == 1` on `_Session.closed`).

### Root cause

CI now resolves pytest 9.2.0, and pytest-xdist 3.8.0 (the latest
release) does not work with it:
- `--dist loadgroup` keeps an `xdist_group` on one worker by rewriting
`item._nodeid` to `<id>@<group>`.
- pytest 9.2 builds `Item.nodeid` from a structured `_id` instead, so
that write is lost.
- Every grouped test is therefore scheduled like an ungrouped one.

The MCP pair (and the other `*_reset_between_tests` pairs) only hold
when both tests run on the same worker. With `-v`, the first test ran on
`gw0` and the second on `gw3`.

Minimal reproduction:

```python
pytestmark = pytest.mark.xdist_group("g1")
def test_one(): pass
def test_two(): pass
```

`pytest -n 2 --dist loadgroup -v`:
- pytest 9.1.1 reports `test_one@g1` and `test_two@g1`, both on `gw0`.
- pytest 9.2.0 reports `test_one` on `gw0` and `test_two` on `gw1`.

The same pytest release is behind the `torch._dynamo.config.* does not
exist` failures (#15624 pins Backend CI below 9.2 for that; #15626 makes
the suite tolerate it).

## Change

This builds on #15624 (merged), which pins `'pytest<9.2'` in
`studio-backend-ci.yml`, the only workflow that runs `--dist loadgroup`.

- **`version-compat-ci.yml`**: `'pytest>=8'` becomes `'pytest>=8,<9.2'`.
These lanes run the CPU-spoof fixtures that monkeypatch
`torch._dynamo.config`, which pytest 9.2 deletes on undo.
- **`tests/_shared/xdist_group_check.py`**, installed as a `trylast`
`pytest_collection_modifyitems` hook in `tests/conftest.py` and
`studio/backend/tests/conftest.py`:
- On an xdist worker running `--dist loadgroup`, any test that carries
an `xdist_group` mark but whose node id has no `@group` tag now fails
with the reason.
- Before, it would sometimes pass and sometimes fail depending on
scheduling. If the pin is lifted before pytest-xdist catches up, the
grouped tests fail by name with an explanation instead of flaking.
- Raising a usage error at collection time would be swallowed into an
xdist `INTERNALERROR`, so each affected test fails individually instead.
- **`tests/test_xdist_group_check.py`**: unit tests for the check, the
conftest wiring, and both pins (Backend CI from #15624 and
version-compat from this PR).

## Testing

Run on `studio/backend/tests/test_mcp_*.py` with `-n 4 --dist
loadgroup`:
- **pytest 9.1.1:** 2089 passed, twice.
- **pytest 9.2.0:** the MCP pair failed in both runs.
- **Serially on 9.2.0:** 2089 passed, so the failure needs xdist.

With the check in place, the two grouped pair files under `-n 2 --dist
loadgroup`:
- **pytest 9.1.1:** 4 passed.
- **pytest 9.2.0:** all 4 grouped tests fail with "--dist loadgroup did
not tag this xdist_group test ...".

`tests/test_xdist_group_check.py` with
`tests/test_torch_config_guard.py` (from #15626) after merging main: 18
passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant