Skip to content

test: fix two tests broken by pytest 9.2.0 - #4222

Merged
winglian merged 3 commits into
mainfrom
fix/pytest-9.2-test-compat
Oct 29, 2026
Merged

winglian merged 3 commits into
mainfrom
fix/pytest-9.2-test-compat

Conversation

@winglian

@winglian winglian commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

pytest 9.2.0, released 2026-10-27, breaks two of main's tests. CI installs pytest unpinned; main's last green runs used 9.1.1.

  • tests/utils/test_moun8bit.py::test_trajectory_tracks_dist_muon: pytest 9.2's approx iterates the expected value to look for Decimal tolerances. The test passed 0-d tensors, so it raised TypeError: iteration over a 0-d tensor. It now compares the losses as floats (.item()).
  • tests/core/trainers/diffusion_lm/test_encoder_canvas.py::test_flex_backend_raises_the_dynamo_recompile_budget: from pytest 9.2, monkeypatch reads the old value statically. It finds nothing on torch._dynamo.config, whose keys go through __getattr__, so its undo calls delattr, and torch's ConfigModule.__delattr__ hides the key. Every later torch.compile on that xdist worker then failed with torch._dynamo.config.recompile_limit does not exist. On CI that showed up in tests/test_chunked_xentropy.py::test_chunked_forward. The test now uses dynamo's own config.patch(recompile_limit=8), which restores the value.

Besides the two test files, the last commit removes the pytest==9.1.1 pin that #4221 added as a stopgap (pyproject.toml's test group, the CPU workflows and both Dockerfiles), so CI runs the latest pytest again. The branch is rebased onto main after #4221.

Motivation and Context

This is maintainer work (Wing). Both failures surfaced while getting CI on #4220 green, and they hit main and every open PR once CI picks up pytest 9.2.0. The same two fixes are on #4220; this PR lands them on main without waiting for it. #4221 pinned pytest==9.1.1 as a stopgap; this PR removes that pin.

How has this been tested?

Locally, on macOS with Python 3.11 and torch 2.14.0, in a venv with pytest 9.2.0:

  • Dynamo key leak: I ran the diffusion test, then a check that torch._dynamo.config still has recompile_limit. With main's version of the test, the check fails; with this branch's, it passes and recompile_limit is back at its default. With pytest 8.4.2, neither version of the test hides the key.
  • approx on tensors: under pytest 9.2.0, tensor(0.501) == pytest.approx(tensor(0.5), rel=1e-2) raises the same TypeError, and the float comparison passes.
  • pre-commit (ruff, ruff-format, mypy, bandit) passes.

Not run locally: test_trajectory_tracks_dist_muon and test_chunked_xentropy need inductor's C++ compile, which fails on this Mac. On #4220, CI ran both with these fixes under pytest 9.2.0 on Python 3.12 / torch 2.13 and Python 3.14 / torch 2.14, and they passed.

AI Usage Disclaimer

Do not open this PR, including as a draft, until a human has reviewed the complete diff. The contributor may perform this review; a separate reviewer is not required. This also applies to maintainer-directed work.

  • A human reviewed the complete diff before this PR was opened, understands the changes, and takes responsibility for them.

Yes. Claude Code (Claude Opus) found the two failures in #4220's CI, traced them to pytest 9.2.0, wrote and verified the fixes, and prepared this branch. Wing reviewed the diff.

Screenshots (if appropriate)

Types of changes

  • Bug fix (tests broken by pytest 9.2.0)

Social Handles (Optional)

Summary by CodeRabbit

  • Tests
    • Updated test setup to restore the existing Dynamo recompilation limit after checks.
    • Adjusted a quantized-loss comparison to compare scalar values.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a342455 and da3c56d.

Files selected for processing: 2
  • tests/core/trainers/diffusion_lm/test_encoder_canvas.py
  • tests/utils/test_moun8bit.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

Two tests now use explicit scalar or configuration handling. The Dynamo test uses a configuration patch context, and the trajectory test compares the quantized loss value.

Changes: Dynamo recompile limit test

Layer / File(s) Summary
Dynamo limit setup and checks
tests/core/trainers/diffusion_lm/test_encoder_canvas.py
The test uses torch._dynamo.config.patch(recompile_limit=8) and retains checks for dense and flex-attention construction, including preservation of a manually set limit.

Quantized loss comparison

Layer / File(s) Summary
Scalar loss comparison
tests/utils/test_moun8bit.py
The trajectory test compares quant_loss.item() with the dense loss using the existing approximate tolerance.

Priority: Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: ved1beta

Merge Risk: Minimal · previous review da3c5

The test updates are ready to merge; reported CI coverage passed with the fixes.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: updating two tests to address breakage caused by pytest 9.2.0.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

pytest 9.2's approx iterates the expected value to check for Decimal
tolerances, which raises on the 0-d tensors _step returns.
From pytest 9.2, monkeypatch reads the old value statically, finds nothing
on torch._dynamo.config (whose keys go through __getattr__) and undoes the
patch with delattr, which hides the key: every later compile on that xdist
worker failed with "torch._dynamo.config.recompile_limit does not exist"
(test_chunked_xentropy on CI). Dynamo's own config.patch restores it.
The 9.1.1 pin from #4221 was a stopgap for the two tests fixed in this branch.
With them passing under pytest 9.2, CI goes back to the latest pytest.
@winglian
winglian force-pushed the fix/pytest-9.2-test-compat branch from da3c56d to 2c756e7 Compare October 29, 2026 09:06
@winglian
winglian merged commit 93575ed into main Oct 29, 2026
20 checks passed
@winglian
winglian deleted the fix/pytest-9.2-test-compat branch October 29, 2026 12:27
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