Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (1): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202385
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 153a4ef with merge base 155e7c4 ( 🟢 GREEN LIGHT - PR approved to be merged without human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
There was a problem hiding this comment.
Automated review of 153a4ef: nothing blocking; ready for human review.
The PR reinstalls pytest==9.1.1 after the TorchBench, HuggingFace and timm installs in install_inductor_benchmark_deps.sh, because pytest 9.2.0 breaks the LogXMLReruns junitxml override in test/conftest.py. The fix is correct and in the right place, but nothing tracks when the pin should be removed. Recommendation: Approve.
⚪ 1 non-blocking finding
The comment explains why the pin exists, but it doesn't link to an issue or say when to remove it. The real fix is a separate follow-up: LogXMLReruns.node_reporter (test/conftest.py:264-280) stores reporters under the string nodeid, but pytest 9.2's LogXML.finalize pops them using a NodeId key. Without a tracking issue, this exact-version pin will probably stay indefinitely. That means (1) the benchmark images stay on 9.1.1 while TorchBench and pytest-benchmark move on, so a future TorchBench bump that needs pytest>9.1.1 would be silently downgraded by this line, and the failure would be hard to trace; (2) the conftest incompatibility stays hidden, and anyone running test/ locally with pytest>=9.2 and reruns enabled will still hit it. Please file the follow-up issue for making LogXMLReruns work with pytest 9.2 and put its URL in this comment, e.g. # TODO(issue URL): drop once test/conftest.py LogXMLReruns supports pytest 9.2+.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
…#202385)" This reverts commit 87845d7. That pin was a stopgap for the test/conftest.py LogXMLReruns KeyError on pytest 9.2.0 (pytorch#202385 itself flagged "making the conftest override compatible with pytest 9.2 is a separate follow-up"). The previous commit on this branch is that follow-up, so drop the pin here to let CI exercise the actual fix end-to-end: the inductor-benchmarks images will go back to picking up whatever pytest TorchBench's unpinned requirements.txt resolves (pytest 9.2.0+ as of this writing), and the conftest.py fix should keep those jobs green without it.
Also make TestJunitXml check this on every pytest version. setUpClass used to skip the whole class unless the installed pytest and pytest-rerunfailures matched the goldens' (the CI pins), so no test could see this crash. Now it records that reason and still runs the fixture suite: only the exact golden comparisons skip. The tag counts move out of test_pytest_outcome_shapes into test_pytest_outcome_counts, which runs on every version, also checks for INTERNALERROR, and skips only when pytest-rerunfailures is missing. With the conftest change it passes on pytest 9.2; without it, it fails there. Also revert #202385, which pinned pytest==9.1.1 in the inductor-benchmarks images as a stopgap for this crash. ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` Authored with an AI assistant (Claude).
Also make TestJunitXml check this on every pytest version. setUpClass used to skip the whole class unless the installed pytest and pytest-rerunfailures matched the goldens' (the CI pins), so no test could see this crash. Now it records that reason and still runs the fixture suite: only the exact golden comparisons skip. The tag counts move out of test_pytest_outcome_shapes into test_pytest_outcome_counts, which runs on every version, also checks for INTERNALERROR, and skips only when pytest-rerunfailures is missing. With the conftest change it passes on pytest 9.2; without it, it fails there. Also revert #202385, which pinned pytest==9.1.1 in the inductor-benchmarks images as a stopgap for this crash. ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` Authored with an AI assistant (Claude).
## Human Note
I tried getting rid of the custom class entirely but Claude persuaded me it was useful. So we're just going to subclass from pytest so we can track upstream more easily.
## Agent Report
### Problem
With pytest 9.2.0, any test run that writes `--junit-xml-reruns` (every CI test shard) aborts with an INTERNALERROR at the first test's teardown:
```
File "test/conftest.py", line 254, in pytest_runtest_logreport
super().pytest_runtest_logreport(report)
File "_pytest/junitxml.py", line 544, in finalize
reporter = self.node_reporters.pop((node_id, workernode))
KeyError: (NodeId(path='test/test_pytree.py', names=('TestGenericPytree', 'test_aligned_public_apis'), params=None), None)
```
### Root cause
`LogXMLReruns.node_reporter` was a copy of pytest's `LogXML.node_reporter`. The copy only differed in building a `_NodeReporterReruns` and stored reporters under `(report.nodeid, workernode)`, with `nodeid` as a string. pytest 9.2 keys `node_reporters` by a new `NodeId` dataclass (`report.id`), and `LogXML.finalize` pops with that key. A `NodeId` never equals a string, so the pop fails.
### Fix
Call `super().node_reporter(report)` so pytest builds the key and the reporter in whatever form that version uses, check that `_NodeReporterReruns` subclasses the returned type, then set the reporter's `__class__` to `_NodeReporterReruns`. The class docstring now says it may only override methods, not add state or change how instance data is represented. The subclass only overrides output methods (`_prepare_content`, `_write_content`, `append_skipped`) and adds no state, so switching the class in place is safe, and it removes the copy of pytest internals that went stale. I also added a docstring to `_NodeReporterReruns` explaining why it exists. pytest.ini sets `junit_logging_reruns = all`, and with the stock `_NodeReporter` every testcase, including passing tests that print nothing, gets a headed `<system-out>` and `<system-err>` element (skipped tests get both twice). The subclass writes captured output raw and omits empty streams. Regenerating the goldens without the subclass shows exactly that difference. The other option, branching on the pytest version to build the right key type, would keep the copy and break again the next time pytest changes the key.
This also reverts #202385, which pinned `pytest==9.1.1` in the inductor-benchmarks images as a stopgap for this crash (TorchBench's requirements pull in an unpinned pytest). The other pytest 9.2 fixes still open shouldn't affect those images: #202406 (`--subprocess` test ids) only matters for the few test modules that `run_test.py` runs with `--subprocess`, which are CUDA-init and distributed tests the inductor configs don't run, and #202412 only restores the teardown part of the RERUNS terminal summary.
### Test
`TestJunitXml` (test/test_testing.py) used to skip on every pytest version except the goldens' (the CI pins), so no test could see this crash. `setUpClass` now records that skip reason instead of raising and still runs the fixture suite; only the exact golden comparisons skip on other versions. The tag counts move out of `test_pytest_outcome_shapes` into `test_pytest_outcome_counts`, which runs on every version and also checks for INTERNALERROR. On pytest 9.2.0 the counts test passes with this change and fails without it; on 7.3.2 (the CI pin) all three tests pass.
#### Where the versions come from
Running the fixture suite on every version means `setUpClass` now depends on the environment in ways the old blanket skip hid, so the version checks have to describe the process that actually runs the suite. That process is a child (`sys.executable -m pytest`) with `PYTHONPATH` removed, so the parent's view can be wrong. Asking the parent with `importlib.metadata` would mean:
- With pytest only on the parent's `PYTHONPATH`, the parent sees pytest, the child doesn't, writes no XML, and `setUpClass` raises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance).
- With a different pytest on the parent's `PYTHONPATH`, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail.
So `setUpClass` first runs a small probe, `_junit_child_versions()`, in the child's interpreter and environment: it prints the pytest and pytest-rerunfailures versions (or null) as JSON via `importlib.metadata`, without importing torch. That one result decides all three things: the class skips when pytest is missing, the counts test skips when pytest-rerunfailures is missing, and the golden header is built from it. The probe costs about 60 ms once per class, next to roughly 3.5 s for the fixture suite run the class already does. The alternatives were matching `No module named pytest` in the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing the `plugins:` line from pytest's console header (fragile, and only saves those 60 ms).
The child also drops `PYTEST_PLUGINS` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD`, as it already drops `PYTEST_ADDOPTS`, so it loads the installed plugins as CI does; with autoload off, pytest-rerunfailures was importable but never loaded and the counts were wrong.
Checked in throwaway environments that really have each version (a `PYTHONPATH` overlay only changes the parent):
| Child environment | Result |
|---|---|
| no pytest | class skipped |
| pytest 9.1.1, no pytest-rerunfailures | all three skip |
| pytest 9.2.0 + pytest-rerunfailures 14.0 | counts pass, goldens skip; counts fail with the old conftest |
| pytest 7.3.2 + pytest-rerunfailures 14.0 | all three pass |
| job venv with pytest 7.3.2 on the parent's `PYTHONPATH`, or `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1` | counts pass, goldens skip |
```
cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml
```
### Validation
A minimal test file covering pass, skip, a flaky test that passes on rerun, a consistent failure with reruns, and an expected failure, run with `--reruns=2 --junit-xml-reruns`, serially and with `-n 2`, under pytest 7.3.2 (requirements-ci pin), 9.1.1 and 9.2.0. pytest-rerunfailures 14.0 and pytest-xdist 3.3.1 are the CI versions. In all six configurations the testcase/rerun/skipped/failure elements of the rerun XML match those the unmodified conftest produces under 9.1.1. Unmodified conftest under 9.2.0 crashes with the KeyError above.
```
PYTHONPATH=<overlay with pytest==$V pytest-rerunfailures==14.0 pytest-xdist==3.3.1> python -m pytest -q -p no:cacheprovider test_mini.py --reruns=2 [-n 2] --junit-xml-reruns=out/r.xml
```
Real test file with each pytest version: 251 passed and 251 testcases in the XML, no INTERNALERROR. The same command with the old conftest on 9.2.0 crashes after the first test.
```
cd test && PYTHONPATH=<overlay pytest==$V> python -m pytest -q -p no:cacheprovider test_pytree.py --reruns=2 -x --junit-xml-reruns=/tmp/rr/r.xml
```
The existing golden fixture `test/junit_xml_testdata/pytest_suite.py` (13 outcome shapes, normalized the same way `TestJunitXml` in `test/test_testing.py` does):
- pytest 7.3.2: the new conftest output matches the committed golden `expected/pytest.xml`, which was recorded with pytest 7.3.2.
- pytest 9.1.1: the new conftest output is identical to the old conftest's.
- pytest 9.2.0: the new conftest output is identical to the old conftest's output under 9.1.1. The old conftest crashes with 81 INTERNALERRORs.
The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above.
`lintrunner test/conftest.py` is clean.
<details>
<summary>Agent Worklog</summary>
# Worklog
- 2026-10-28: Diffed pytest 9.1.1 and 9.2.0 `_pytest/junitxml.py`. `node_reporters` is now keyed by a `NodeId` dataclass (`report.id`); `finalize` pops `(report.id, workernode)`. conftest's copied `node_reporter` used string nodeids, so it fails at the first teardown, not only on reruns.
- Reproduced with a minimal test file under overlays of pytest 7.3.2/9.1.1/9.2.0 on the job venv's torch.
- Fix: delegate to `super().node_reporter` and set `__class__ = _NodeReporterReruns`. The XML matches the old behavior under all three versions, serial and with xdist. `test_pytree.py` passes under all three. lintrunner is clean.
- Golden fixture junit_xml_testdata/pytest_suite.py: new==golden on 7.3.2, new==old on 9.1.1, new on 9.2.0 == old on 9.1.1.
- 2026-10-29: (superseded) C1 test change moved to its own PR, see below.
- 2026-10-29: split the C1 test change into job 20261029-pytorch-adhoc-7dcc5b (new PR below this one); this branch now sits on ptq/20261029-pytorch-adhoc-7dcc5b. Counts test passes on 9.2.0 with this fix. Not pushed.
- 2026-10-29: now on the refactor 7879242; this PR moves the version skip onto the goldens and runs the counts (plus an INTERNALERROR check) on every version. Commit d334d9d. 9.2.0: counts pass with the fix, fail without.
- 2026-10-29: shrank the test change: setUpClass unchanged except it records the version-mismatch reason (golden_skip) instead of raising, and keeps proc output; goldens skip on it; counts add an INTERNALERROR check. Commit 980d40eddfd. 7.3.2 all pass; 9.2.0 counts pass (fail without the conftest fix), goldens skip.
- 2026-10-29: consolidated (Edward OK): #202597 closed, this PR retargeted to main, single commit de4b8db pushed, body Test section updated.
- 2026-10-29: automated review flagged the pytest==9.1.1 pin from #202385 in install_inductor_benchmark_deps.sh as stale. Rebased onto origin/main 92264e2 and removed the pin (exact revert of #202385). TestJunitXml: 9.1.1 venv and 9.2.0 overlay pass (goldens skip); the 7.3.2 golden diffs I saw were my overlay run missing the repo-root pytest.ini; the PR-review agent confirmed old and new conftest match the goldens on 7.3.2 run in place. Not pushed.
- 2026-10-30: Edward approved; pushed 1d11f93 via git (ssh). PR body not yet regenerated: gh on devgpu013 is logged out (~/.config/gh/hosts.yml emptied 2026-10-30 06:20). Body regenerated with ptq pr on 2026-10-30 after gh re-auth.
- 2026-10-30: automated review of 1d11f93: without pytest installed, TestJunitXml errored (subprocess ran, no XML) instead of skipping. setUpClass now raises SkipTest first when pytest is missing. Verified with _junit_provenance patched to "pytest missing" (class skipped, subprocess not run); 9.1.1 venv and 9.2.0 overlay unchanged; lint clean.
- 2026-10-30: per Edward, replaced the provenance-string checks: setUpClass skips when the child stderr has "No module named pytest" (no XML), and the counts test probes `import pytest_rerunfailures` with the child env. Note: earlier PYTHONPATH-overlay runs of TestJunitXml only changed the parent; the child drops PYTHONPATH and used the venv pytest 9.1.1. Re-verified with symlinked throwaway venvs: 9.2.0 counts pass (fail with origin/main conftest), 7.3.2 all pass, no pytest -> class skipped, no rerunfailures -> all skip.
- 2026-10-30: replaced the stderr match and import probe with one child probe (_junit_child_versions, JSON of pytest/rerunfailures versions under _JUNIT_CHILD_ENV): it drives the class skip, has_rerunfailures, and the golden provenance (fixes parent/child mismatch under PYTHONPATH). Child env also drops PYTEST_PLUGINS/PYTEST_DISABLE_PLUGIN_AUTOLOAD. Verified: no pytest -> class skip; no rerunfailures -> 3 skips; 9.2.0 counts pass (fail with origin/main conftest); 7.3.2 all pass; job venv with PYTHONPATH=ov-7.3.2 or PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 -> OK.
</details>
---
*This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.*
Pull Request resolved: #202390
Approved by: https://github.com/nWEIdia, https://github.com/atalman, https://github.com/huydhn, https://github.com/jeanschmidt
## Human Note
pytest 9.2.0 breaks inductor-periodic, pin the last known working version
## Agent Report
### Problem
Since pytest 9.2.0 was released (2026-10-27), every job on a `*-inductor-benchmarks` CI image (inductor-periodic `benchmarks-cpu-test inductor_avx2`, inductor `inductor-cpu-test` amx/aoti_fallback, `inductor-test-cuda132` cpp_wrapper/distributed) aborts its pytest session the first time a test is rerun:
```
test/conftest.py:254 in pytest_runtest_logreport
_pytest/junitxml.py:544 in finalize: reporter = self.node_reporters.pop((node_id, workernode))
KeyError: (NodeId(path='test/test_torch.py', names=('TestTorchDeviceTypeCPU', 'test_diff_cpu_float16'), params=None), None)
```
The test HUD names is whichever test happened to be running at the time.
### Root cause
`requirements-ci.txt` pins `pytest==7.3.2`, but `install_inductor_benchmark_deps.sh` runs TorchBench's `install.py`, whose `requirements.txt` lists an unpinned `pytest` (and `pytest-benchmark`). The benchmarks images therefore carry whatever pytest is newest when the image is built: 9.1.1 in the last green runs, 9.2.0 after the images were rebuilt on 2026-10-28. In pytest 9.2.0, `LogXML.finalize` pops reporters by a `NodeId` key, while `LogXMLReruns.node_reporter` in `test/conftest.py` stores them under the string nodeid, so the pop fails for rerun reports.
### Fix
Reinstall `pytest==9.1.1` after the TorchBench/HuggingFace/timm installs. That restores the exact version the benchmarks images had while green. Pinning to the repo-wide 7.3.2 instead is not an option: `pytest-benchmark` 5.3.0, which TorchBench installs, requires pytest>=8.1. Making the conftest override compatible with pytest 9.2 is a separate follow-up.
### Validation
- `bash -n` and shellcheck lint on the changed script.
- Compared CI logs on the same image tag: the last green inductor-periodic avx2 run reports `pytest-9.1.1`, and every failing run reports `pytest-9.2.0` together with the junitxml KeyError.
- The real test is the docker-builds and inductor jobs on this PR, which rebuild the images.
<details>
<summary>Agent Worklog</summary>
# Worklog
- 2026-10-28: OSS CI check found Inductor Periodic RED. Every failing log on an inductor-benchmarks image shows pytest-9.2.0 plus a junitxml KeyError from test/conftest.py LogXMLReruns. The last green run on the same tag `e5ceb2` had pytest-9.1.1. TorchBench pin c5ea24d7 requirements.txt lists an unpinned `pytest`. No fix PR or tracking issue existed.
- Pinned `pytest==9.1.1` in `.ci/docker/common/install_inductor_benchmark_deps.sh` after the benchmark installs. Lint is clean.
</details>
---
*This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.*
Pull Request resolved: pytorch#202385
Approved by: https://github.com/pytorchgreenlight
…h#202390) ## Human Note I tried getting rid of the custom class entirely but Claude persuaded me it was useful. So we're just going to subclass from pytest so we can track upstream more easily. ## Agent Report ### Problem With pytest 9.2.0, any test run that writes `--junit-xml-reruns` (every CI test shard) aborts with an INTERNALERROR at the first test's teardown: ``` File "test/conftest.py", line 254, in pytest_runtest_logreport super().pytest_runtest_logreport(report) File "_pytest/junitxml.py", line 544, in finalize reporter = self.node_reporters.pop((node_id, workernode)) KeyError: (NodeId(path='test/test_pytree.py', names=('TestGenericPytree', 'test_aligned_public_apis'), params=None), None) ``` ### Root cause `LogXMLReruns.node_reporter` was a copy of pytest's `LogXML.node_reporter`. The copy only differed in building a `_NodeReporterReruns` and stored reporters under `(report.nodeid, workernode)`, with `nodeid` as a string. pytest 9.2 keys `node_reporters` by a new `NodeId` dataclass (`report.id`), and `LogXML.finalize` pops with that key. A `NodeId` never equals a string, so the pop fails. ### Fix Call `super().node_reporter(report)` so pytest builds the key and the reporter in whatever form that version uses, check that `_NodeReporterReruns` subclasses the returned type, then set the reporter's `__class__` to `_NodeReporterReruns`. The class docstring now says it may only override methods, not add state or change how instance data is represented. The subclass only overrides output methods (`_prepare_content`, `_write_content`, `append_skipped`) and adds no state, so switching the class in place is safe, and it removes the copy of pytest internals that went stale. I also added a docstring to `_NodeReporterReruns` explaining why it exists. pytest.ini sets `junit_logging_reruns = all`, and with the stock `_NodeReporter` every testcase, including passing tests that print nothing, gets a headed `<system-out>` and `<system-err>` element (skipped tests get both twice). The subclass writes captured output raw and omits empty streams. Regenerating the goldens without the subclass shows exactly that difference. The other option, branching on the pytest version to build the right key type, would keep the copy and break again the next time pytest changes the key. This also reverts pytorch#202385, which pinned `pytest==9.1.1` in the inductor-benchmarks images as a stopgap for this crash (TorchBench's requirements pull in an unpinned pytest). The other pytest 9.2 fixes still open shouldn't affect those images: pytorch#202406 (`--subprocess` test ids) only matters for the few test modules that `run_test.py` runs with `--subprocess`, which are CUDA-init and distributed tests the inductor configs don't run, and pytorch#202412 only restores the teardown part of the RERUNS terminal summary. ### Test `TestJunitXml` (test/test_testing.py) used to skip on every pytest version except the goldens' (the CI pins), so no test could see this crash. `setUpClass` now records that skip reason instead of raising and still runs the fixture suite; only the exact golden comparisons skip on other versions. The tag counts move out of `test_pytest_outcome_shapes` into `test_pytest_outcome_counts`, which runs on every version and also checks for INTERNALERROR. On pytest 9.2.0 the counts test passes with this change and fails without it; on 7.3.2 (the CI pin) all three tests pass. #### Where the versions come from Running the fixture suite on every version means `setUpClass` now depends on the environment in ways the old blanket skip hid, so the version checks have to describe the process that actually runs the suite. That process is a child (`sys.executable -m pytest`) with `PYTHONPATH` removed, so the parent's view can be wrong. Asking the parent with `importlib.metadata` would mean: - With pytest only on the parent's `PYTHONPATH`, the parent sees pytest, the child doesn't, writes no XML, and `setUpClass` raises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance). - With a different pytest on the parent's `PYTHONPATH`, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail. So `setUpClass` first runs a small probe, `_junit_child_versions()`, in the child's interpreter and environment: it prints the pytest and pytest-rerunfailures versions (or null) as JSON via `importlib.metadata`, without importing torch. That one result decides all three things: the class skips when pytest is missing, the counts test skips when pytest-rerunfailures is missing, and the golden header is built from it. The probe costs about 60 ms once per class, next to roughly 3.5 s for the fixture suite run the class already does. The alternatives were matching `No module named pytest` in the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing the `plugins:` line from pytest's console header (fragile, and only saves those 60 ms). The child also drops `PYTEST_PLUGINS` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD`, as it already drops `PYTEST_ADDOPTS`, so it loads the installed plugins as CI does; with autoload off, pytest-rerunfailures was importable but never loaded and the counts were wrong. Checked in throwaway environments that really have each version (a `PYTHONPATH` overlay only changes the parent): | Child environment | Result | |---|---| | no pytest | class skipped | | pytest 9.1.1, no pytest-rerunfailures | all three skip | | pytest 9.2.0 + pytest-rerunfailures 14.0 | counts pass, goldens skip; counts fail with the old conftest | | pytest 7.3.2 + pytest-rerunfailures 14.0 | all three pass | | job venv with pytest 7.3.2 on the parent's `PYTHONPATH`, or `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1` | counts pass, goldens skip | ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` ### Validation A minimal test file covering pass, skip, a flaky test that passes on rerun, a consistent failure with reruns, and an expected failure, run with `--reruns=2 --junit-xml-reruns`, serially and with `-n 2`, under pytest 7.3.2 (requirements-ci pin), 9.1.1 and 9.2.0. pytest-rerunfailures 14.0 and pytest-xdist 3.3.1 are the CI versions. In all six configurations the testcase/rerun/skipped/failure elements of the rerun XML match those the unmodified conftest produces under 9.1.1. Unmodified conftest under 9.2.0 crashes with the KeyError above. ``` PYTHONPATH=<overlay with pytest==$V pytest-rerunfailures==14.0 pytest-xdist==3.3.1> python -m pytest -q -p no:cacheprovider test_mini.py --reruns=2 [-n 2] --junit-xml-reruns=out/r.xml ``` Real test file with each pytest version: 251 passed and 251 testcases in the XML, no INTERNALERROR. The same command with the old conftest on 9.2.0 crashes after the first test. ``` cd test && PYTHONPATH=<overlay pytest==$V> python -m pytest -q -p no:cacheprovider test_pytree.py --reruns=2 -x --junit-xml-reruns=/tmp/rr/r.xml ``` The existing golden fixture `test/junit_xml_testdata/pytest_suite.py` (13 outcome shapes, normalized the same way `TestJunitXml` in `test/test_testing.py` does): - pytest 7.3.2: the new conftest output matches the committed golden `expected/pytest.xml`, which was recorded with pytest 7.3.2. - pytest 9.1.1: the new conftest output is identical to the old conftest's. - pytest 9.2.0: the new conftest output is identical to the old conftest's output under 9.1.1. The old conftest crashes with 81 INTERNALERRORs. The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above. `lintrunner test/conftest.py` is clean. <details> <summary>Agent Worklog</summary> # Worklog - 2026-10-28: Diffed pytest 9.1.1 and 9.2.0 `_pytest/junitxml.py`. `node_reporters` is now keyed by a `NodeId` dataclass (`report.id`); `finalize` pops `(report.id, workernode)`. conftest's copied `node_reporter` used string nodeids, so it fails at the first teardown, not only on reruns. - Reproduced with a minimal test file under overlays of pytest 7.3.2/9.1.1/9.2.0 on the job venv's torch. - Fix: delegate to `super().node_reporter` and set `__class__ = _NodeReporterReruns`. The XML matches the old behavior under all three versions, serial and with xdist. `test_pytree.py` passes under all three. lintrunner is clean. - Golden fixture junit_xml_testdata/pytest_suite.py: new==golden on 7.3.2, new==old on 9.1.1, new on 9.2.0 == old on 9.1.1. - 2026-10-29: (superseded) C1 test change moved to its own PR, see below. - 2026-10-29: split the C1 test change into job 20261029-pytorch-adhoc-7dcc5b (new PR below this one); this branch now sits on ptq/20261029-pytorch-adhoc-7dcc5b. Counts test passes on 9.2.0 with this fix. Not pushed. - 2026-10-29: now on the refactor 7879242; this PR moves the version skip onto the goldens and runs the counts (plus an INTERNALERROR check) on every version. Commit d334d9d. 9.2.0: counts pass with the fix, fail without. - 2026-10-29: shrank the test change: setUpClass unchanged except it records the version-mismatch reason (golden_skip) instead of raising, and keeps proc output; goldens skip on it; counts add an INTERNALERROR check. Commit 980d40eddfd. 7.3.2 all pass; 9.2.0 counts pass (fail without the conftest fix), goldens skip. - 2026-10-29: consolidated (Edward OK): pytorch#202597 closed, this PR retargeted to main, single commit de4b8db pushed, body Test section updated. - 2026-10-29: automated review flagged the pytest==9.1.1 pin from pytorch#202385 in install_inductor_benchmark_deps.sh as stale. Rebased onto origin/main 92264e2 and removed the pin (exact revert of pytorch#202385). TestJunitXml: 9.1.1 venv and 9.2.0 overlay pass (goldens skip); the 7.3.2 golden diffs I saw were my overlay run missing the repo-root pytest.ini; the PR-review agent confirmed old and new conftest match the goldens on 7.3.2 run in place. Not pushed. - 2026-10-30: Edward approved; pushed 1d11f93 via git (ssh). PR body not yet regenerated: gh on devgpu013 is logged out (~/.config/gh/hosts.yml emptied 2026-10-30 06:20). Body regenerated with ptq pr on 2026-10-30 after gh re-auth. - 2026-10-30: automated review of 1d11f93: without pytest installed, TestJunitXml errored (subprocess ran, no XML) instead of skipping. setUpClass now raises SkipTest first when pytest is missing. Verified with _junit_provenance patched to "pytest missing" (class skipped, subprocess not run); 9.1.1 venv and 9.2.0 overlay unchanged; lint clean. - 2026-10-30: per Edward, replaced the provenance-string checks: setUpClass skips when the child stderr has "No module named pytest" (no XML), and the counts test probes `import pytest_rerunfailures` with the child env. Note: earlier PYTHONPATH-overlay runs of TestJunitXml only changed the parent; the child drops PYTHONPATH and used the venv pytest 9.1.1. Re-verified with symlinked throwaway venvs: 9.2.0 counts pass (fail with origin/main conftest), 7.3.2 all pass, no pytest -> class skipped, no rerunfailures -> all skip. - 2026-10-30: replaced the stderr match and import probe with one child probe (_junit_child_versions, JSON of pytest/rerunfailures versions under _JUNIT_CHILD_ENV): it drives the class skip, has_rerunfailures, and the golden provenance (fixes parent/child mismatch under PYTHONPATH). Child env also drops PYTEST_PLUGINS/PYTEST_DISABLE_PLUGIN_AUTOLOAD. Verified: no pytest -> class skip; no rerunfailures -> 3 skips; 9.2.0 counts pass (fail with origin/main conftest); 7.3.2 all pass; job venv with PYTHONPATH=ov-7.3.2 or PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 -> OK. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202390 Approved by: https://github.com/nWEIdia, https://github.com/atalman, https://github.com/huydhn, https://github.com/jeanschmidt
## Human Note
pytest 9.2.0 breaks inductor-periodic, pin the last known working version
## Agent Report
### Problem
Since pytest 9.2.0 was released (2026-10-27), every job on a `*-inductor-benchmarks` CI image (inductor-periodic `benchmarks-cpu-test inductor_avx2`, inductor `inductor-cpu-test` amx/aoti_fallback, `inductor-test-cuda132` cpp_wrapper/distributed) aborts its pytest session the first time a test is rerun:
```
test/conftest.py:254 in pytest_runtest_logreport
_pytest/junitxml.py:544 in finalize: reporter = self.node_reporters.pop((node_id, workernode))
KeyError: (NodeId(path='test/test_torch.py', names=('TestTorchDeviceTypeCPU', 'test_diff_cpu_float16'), params=None), None)
```
The test HUD names is whichever test happened to be running at the time.
### Root cause
`requirements-ci.txt` pins `pytest==7.3.2`, but `install_inductor_benchmark_deps.sh` runs TorchBench's `install.py`, whose `requirements.txt` lists an unpinned `pytest` (and `pytest-benchmark`). The benchmarks images therefore carry whatever pytest is newest when the image is built: 9.1.1 in the last green runs, 9.2.0 after the images were rebuilt on 2026-10-28. In pytest 9.2.0, `LogXML.finalize` pops reporters by a `NodeId` key, while `LogXMLReruns.node_reporter` in `test/conftest.py` stores them under the string nodeid, so the pop fails for rerun reports.
### Fix
Reinstall `pytest==9.1.1` after the TorchBench/HuggingFace/timm installs. That restores the exact version the benchmarks images had while green. Pinning to the repo-wide 7.3.2 instead is not an option: `pytest-benchmark` 5.3.0, which TorchBench installs, requires pytest>=8.1. Making the conftest override compatible with pytest 9.2 is a separate follow-up.
### Validation
- `bash -n` and shellcheck lint on the changed script.
- Compared CI logs on the same image tag: the last green inductor-periodic avx2 run reports `pytest-9.1.1`, and every failing run reports `pytest-9.2.0` together with the junitxml KeyError.
- The real test is the docker-builds and inductor jobs on this PR, which rebuild the images.
<details>
<summary>Agent Worklog</summary>
# Worklog
- 2026-10-28: OSS CI check found Inductor Periodic RED. Every failing log on an inductor-benchmarks image shows pytest-9.2.0 plus a junitxml KeyError from test/conftest.py LogXMLReruns. The last green run on the same tag `e5ceb2` had pytest-9.1.1. TorchBench pin c5ea24d7 requirements.txt lists an unpinned `pytest`. No fix PR or tracking issue existed.
- Pinned `pytest==9.1.1` in `.ci/docker/common/install_inductor_benchmark_deps.sh` after the benchmark installs. Lint is clean.
</details>
---
*This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.*
Pull Request resolved: pytorch#202385
Approved by: https://github.com/pytorchgreenlight
…h#202390) ## Human Note I tried getting rid of the custom class entirely but Claude persuaded me it was useful. So we're just going to subclass from pytest so we can track upstream more easily. ## Agent Report ### Problem With pytest 9.2.0, any test run that writes `--junit-xml-reruns` (every CI test shard) aborts with an INTERNALERROR at the first test's teardown: ``` File "test/conftest.py", line 254, in pytest_runtest_logreport super().pytest_runtest_logreport(report) File "_pytest/junitxml.py", line 544, in finalize reporter = self.node_reporters.pop((node_id, workernode)) KeyError: (NodeId(path='test/test_pytree.py', names=('TestGenericPytree', 'test_aligned_public_apis'), params=None), None) ``` ### Root cause `LogXMLReruns.node_reporter` was a copy of pytest's `LogXML.node_reporter`. The copy only differed in building a `_NodeReporterReruns` and stored reporters under `(report.nodeid, workernode)`, with `nodeid` as a string. pytest 9.2 keys `node_reporters` by a new `NodeId` dataclass (`report.id`), and `LogXML.finalize` pops with that key. A `NodeId` never equals a string, so the pop fails. ### Fix Call `super().node_reporter(report)` so pytest builds the key and the reporter in whatever form that version uses, check that `_NodeReporterReruns` subclasses the returned type, then set the reporter's `__class__` to `_NodeReporterReruns`. The class docstring now says it may only override methods, not add state or change how instance data is represented. The subclass only overrides output methods (`_prepare_content`, `_write_content`, `append_skipped`) and adds no state, so switching the class in place is safe, and it removes the copy of pytest internals that went stale. I also added a docstring to `_NodeReporterReruns` explaining why it exists. pytest.ini sets `junit_logging_reruns = all`, and with the stock `_NodeReporter` every testcase, including passing tests that print nothing, gets a headed `<system-out>` and `<system-err>` element (skipped tests get both twice). The subclass writes captured output raw and omits empty streams. Regenerating the goldens without the subclass shows exactly that difference. The other option, branching on the pytest version to build the right key type, would keep the copy and break again the next time pytest changes the key. This also reverts pytorch#202385, which pinned `pytest==9.1.1` in the inductor-benchmarks images as a stopgap for this crash (TorchBench's requirements pull in an unpinned pytest). The other pytest 9.2 fixes still open shouldn't affect those images: pytorch#202406 (`--subprocess` test ids) only matters for the few test modules that `run_test.py` runs with `--subprocess`, which are CUDA-init and distributed tests the inductor configs don't run, and pytorch#202412 only restores the teardown part of the RERUNS terminal summary. ### Test `TestJunitXml` (test/test_testing.py) used to skip on every pytest version except the goldens' (the CI pins), so no test could see this crash. `setUpClass` now records that skip reason instead of raising and still runs the fixture suite; only the exact golden comparisons skip on other versions. The tag counts move out of `test_pytest_outcome_shapes` into `test_pytest_outcome_counts`, which runs on every version and also checks for INTERNALERROR. On pytest 9.2.0 the counts test passes with this change and fails without it; on 7.3.2 (the CI pin) all three tests pass. #### Where the versions come from Running the fixture suite on every version means `setUpClass` now depends on the environment in ways the old blanket skip hid, so the version checks have to describe the process that actually runs the suite. That process is a child (`sys.executable -m pytest`) with `PYTHONPATH` removed, so the parent's view can be wrong. Asking the parent with `importlib.metadata` would mean: - With pytest only on the parent's `PYTHONPATH`, the parent sees pytest, the child doesn't, writes no XML, and `setUpClass` raises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance). - With a different pytest on the parent's `PYTHONPATH`, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail. So `setUpClass` first runs a small probe, `_junit_child_versions()`, in the child's interpreter and environment: it prints the pytest and pytest-rerunfailures versions (or null) as JSON via `importlib.metadata`, without importing torch. That one result decides all three things: the class skips when pytest is missing, the counts test skips when pytest-rerunfailures is missing, and the golden header is built from it. The probe costs about 60 ms once per class, next to roughly 3.5 s for the fixture suite run the class already does. The alternatives were matching `No module named pytest` in the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing the `plugins:` line from pytest's console header (fragile, and only saves those 60 ms). The child also drops `PYTEST_PLUGINS` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD`, as it already drops `PYTEST_ADDOPTS`, so it loads the installed plugins as CI does; with autoload off, pytest-rerunfailures was importable but never loaded and the counts were wrong. Checked in throwaway environments that really have each version (a `PYTHONPATH` overlay only changes the parent): | Child environment | Result | |---|---| | no pytest | class skipped | | pytest 9.1.1, no pytest-rerunfailures | all three skip | | pytest 9.2.0 + pytest-rerunfailures 14.0 | counts pass, goldens skip; counts fail with the old conftest | | pytest 7.3.2 + pytest-rerunfailures 14.0 | all three pass | | job venv with pytest 7.3.2 on the parent's `PYTHONPATH`, or `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1` | counts pass, goldens skip | ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` ### Validation A minimal test file covering pass, skip, a flaky test that passes on rerun, a consistent failure with reruns, and an expected failure, run with `--reruns=2 --junit-xml-reruns`, serially and with `-n 2`, under pytest 7.3.2 (requirements-ci pin), 9.1.1 and 9.2.0. pytest-rerunfailures 14.0 and pytest-xdist 3.3.1 are the CI versions. In all six configurations the testcase/rerun/skipped/failure elements of the rerun XML match those the unmodified conftest produces under 9.1.1. Unmodified conftest under 9.2.0 crashes with the KeyError above. ``` PYTHONPATH=<overlay with pytest==$V pytest-rerunfailures==14.0 pytest-xdist==3.3.1> python -m pytest -q -p no:cacheprovider test_mini.py --reruns=2 [-n 2] --junit-xml-reruns=out/r.xml ``` Real test file with each pytest version: 251 passed and 251 testcases in the XML, no INTERNALERROR. The same command with the old conftest on 9.2.0 crashes after the first test. ``` cd test && PYTHONPATH=<overlay pytest==$V> python -m pytest -q -p no:cacheprovider test_pytree.py --reruns=2 -x --junit-xml-reruns=/tmp/rr/r.xml ``` The existing golden fixture `test/junit_xml_testdata/pytest_suite.py` (13 outcome shapes, normalized the same way `TestJunitXml` in `test/test_testing.py` does): - pytest 7.3.2: the new conftest output matches the committed golden `expected/pytest.xml`, which was recorded with pytest 7.3.2. - pytest 9.1.1: the new conftest output is identical to the old conftest's. - pytest 9.2.0: the new conftest output is identical to the old conftest's output under 9.1.1. The old conftest crashes with 81 INTERNALERRORs. The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above. `lintrunner test/conftest.py` is clean. <details> <summary>Agent Worklog</summary> # Worklog - 2026-10-28: Diffed pytest 9.1.1 and 9.2.0 `_pytest/junitxml.py`. `node_reporters` is now keyed by a `NodeId` dataclass (`report.id`); `finalize` pops `(report.id, workernode)`. conftest's copied `node_reporter` used string nodeids, so it fails at the first teardown, not only on reruns. - Reproduced with a minimal test file under overlays of pytest 7.3.2/9.1.1/9.2.0 on the job venv's torch. - Fix: delegate to `super().node_reporter` and set `__class__ = _NodeReporterReruns`. The XML matches the old behavior under all three versions, serial and with xdist. `test_pytree.py` passes under all three. lintrunner is clean. - Golden fixture junit_xml_testdata/pytest_suite.py: new==golden on 7.3.2, new==old on 9.1.1, new on 9.2.0 == old on 9.1.1. - 2026-10-29: (superseded) C1 test change moved to its own PR, see below. - 2026-10-29: split the C1 test change into job 20261029-pytorch-adhoc-7dcc5b (new PR below this one); this branch now sits on ptq/20261029-pytorch-adhoc-7dcc5b. Counts test passes on 9.2.0 with this fix. Not pushed. - 2026-10-29: now on the refactor 7879242; this PR moves the version skip onto the goldens and runs the counts (plus an INTERNALERROR check) on every version. Commit d334d9d. 9.2.0: counts pass with the fix, fail without. - 2026-10-29: shrank the test change: setUpClass unchanged except it records the version-mismatch reason (golden_skip) instead of raising, and keeps proc output; goldens skip on it; counts add an INTERNALERROR check. Commit 980d40eddfd. 7.3.2 all pass; 9.2.0 counts pass (fail without the conftest fix), goldens skip. - 2026-10-29: consolidated (Edward OK): pytorch#202597 closed, this PR retargeted to main, single commit de4b8db pushed, body Test section updated. - 2026-10-29: automated review flagged the pytest==9.1.1 pin from pytorch#202385 in install_inductor_benchmark_deps.sh as stale. Rebased onto origin/main 92264e2 and removed the pin (exact revert of pytorch#202385). TestJunitXml: 9.1.1 venv and 9.2.0 overlay pass (goldens skip); the 7.3.2 golden diffs I saw were my overlay run missing the repo-root pytest.ini; the PR-review agent confirmed old and new conftest match the goldens on 7.3.2 run in place. Not pushed. - 2026-10-30: Edward approved; pushed 1d11f93 via git (ssh). PR body not yet regenerated: gh on devgpu013 is logged out (~/.config/gh/hosts.yml emptied 2026-10-30 06:20). Body regenerated with ptq pr on 2026-10-30 after gh re-auth. - 2026-10-30: automated review of 1d11f93: without pytest installed, TestJunitXml errored (subprocess ran, no XML) instead of skipping. setUpClass now raises SkipTest first when pytest is missing. Verified with _junit_provenance patched to "pytest missing" (class skipped, subprocess not run); 9.1.1 venv and 9.2.0 overlay unchanged; lint clean. - 2026-10-30: per Edward, replaced the provenance-string checks: setUpClass skips when the child stderr has "No module named pytest" (no XML), and the counts test probes `import pytest_rerunfailures` with the child env. Note: earlier PYTHONPATH-overlay runs of TestJunitXml only changed the parent; the child drops PYTHONPATH and used the venv pytest 9.1.1. Re-verified with symlinked throwaway venvs: 9.2.0 counts pass (fail with origin/main conftest), 7.3.2 all pass, no pytest -> class skipped, no rerunfailures -> all skip. - 2026-10-30: replaced the stderr match and import probe with one child probe (_junit_child_versions, JSON of pytest/rerunfailures versions under _JUNIT_CHILD_ENV): it drives the class skip, has_rerunfailures, and the golden provenance (fixes parent/child mismatch under PYTHONPATH). Child env also drops PYTEST_PLUGINS/PYTEST_DISABLE_PLUGIN_AUTOLOAD. Verified: no pytest -> class skip; no rerunfailures -> 3 skips; 9.2.0 counts pass (fail with origin/main conftest); 7.3.2 all pass; job venv with PYTHONPATH=ov-7.3.2 or PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 -> OK. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202390 Approved by: https://github.com/nWEIdia, https://github.com/atalman, https://github.com/huydhn, https://github.com/jeanschmidt
…est 9.2 (pytorch#202390) (#3936) ## Human Note I tried getting rid of the custom class entirely but Claude persuaded me it was useful. So we're just going to subclass from pytest so we can track upstream more easily. ## Agent Report ### Problem With pytest 9.2.0, any test run that writes `--junit-xml-reruns` (every CI test shard) aborts with an INTERNALERROR at the first test's teardown: ``` File "test/conftest.py", line 254, in pytest_runtest_logreport super().pytest_runtest_logreport(report) File "_pytest/junitxml.py", line 544, in finalize reporter = self.node_reporters.pop((node_id, workernode)) KeyError: (NodeId(path='test/test_pytree.py', names=('TestGenericPytree', 'test_aligned_public_apis'), params=None), None) ``` ### Root cause `LogXMLReruns.node_reporter` was a copy of pytest's `LogXML.node_reporter`. The copy only differed in building a `_NodeReporterReruns` and stored reporters under `(report.nodeid, workernode)`, with `nodeid` as a string. pytest 9.2 keys `node_reporters` by a new `NodeId` dataclass (`report.id`), and `LogXML.finalize` pops with that key. A `NodeId` never equals a string, so the pop fails. ### Fix Call `super().node_reporter(report)` so pytest builds the key and the reporter in whatever form that version uses, check that `_NodeReporterReruns` subclasses the returned type, then set the reporter's `__class__` to `_NodeReporterReruns`. The class docstring now says it may only override methods, not add state or change how instance data is represented. The subclass only overrides output methods (`_prepare_content`, `_write_content`, `append_skipped`) and adds no state, so switching the class in place is safe, and it removes the copy of pytest internals that went stale. I also added a docstring to `_NodeReporterReruns` explaining why it exists. pytest.ini sets `junit_logging_reruns = all`, and with the stock `_NodeReporter` every testcase, including passing tests that print nothing, gets a headed `<system-out>` and `<system-err>` element (skipped tests get both twice). The subclass writes captured output raw and omits empty streams. Regenerating the goldens without the subclass shows exactly that difference. The other option, branching on the pytest version to build the right key type, would keep the copy and break again the next time pytest changes the key. This also reverts pytorch#202385, which pinned `pytest==9.1.1` in the inductor-benchmarks images as a stopgap for this crash (TorchBench's requirements pull in an unpinned pytest). The other pytest 9.2 fixes still open shouldn't affect those images: pytorch#202406 (`--subprocess` test ids) only matters for the few test modules that `run_test.py` runs with `--subprocess`, which are CUDA-init and distributed tests the inductor configs don't run, and pytorch#202412 only restores the teardown part of the RERUNS terminal summary. ### Test `TestJunitXml` (test/test_testing.py) used to skip on every pytest version except the goldens' (the CI pins), so no test could see this crash. `setUpClass` now records that skip reason instead of raising and still runs the fixture suite; only the exact golden comparisons skip on other versions. The tag counts move out of `test_pytest_outcome_shapes` into `test_pytest_outcome_counts`, which runs on every version and also checks for INTERNALERROR. On pytest 9.2.0 the counts test passes with this change and fails without it; on 7.3.2 (the CI pin) all three tests pass. #### Where the versions come from Running the fixture suite on every version means `setUpClass` now depends on the environment in ways the old blanket skip hid, so the version checks have to describe the process that actually runs the suite. That process is a child (`sys.executable -m pytest`) with `PYTHONPATH` removed, so the parent's view can be wrong. Asking the parent with `importlib.metadata` would mean: - With pytest only on the parent's `PYTHONPATH`, the parent sees pytest, the child doesn't, writes no XML, and `setUpClass` raises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance). - With a different pytest on the parent's `PYTHONPATH`, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail. So `setUpClass` first runs a small probe, `_junit_child_versions()`, in the child's interpreter and environment: it prints the pytest and pytest-rerunfailures versions (or null) as JSON via `importlib.metadata`, without importing torch. That one result decides all three things: the class skips when pytest is missing, the counts test skips when pytest-rerunfailures is missing, and the golden header is built from it. The probe costs about 60 ms once per class, next to roughly 3.5 s for the fixture suite run the class already does. The alternatives were matching `No module named pytest` in the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing the `plugins:` line from pytest's console header (fragile, and only saves those 60 ms). The child also drops `PYTEST_PLUGINS` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD`, as it already drops `PYTEST_ADDOPTS`, so it loads the installed plugins as CI does; with autoload off, pytest-rerunfailures was importable but never loaded and the counts were wrong. Checked in throwaway environments that really have each version (a `PYTHONPATH` overlay only changes the parent): | Child environment | Result | |---|---| | no pytest | class skipped | | pytest 9.1.1, no pytest-rerunfailures | all three skip | | pytest 9.2.0 + pytest-rerunfailures 14.0 | counts pass, goldens skip; counts fail with the old conftest | | pytest 7.3.2 + pytest-rerunfailures 14.0 | all three pass | | job venv with pytest 7.3.2 on the parent's `PYTHONPATH`, or `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1` | counts pass, goldens skip | ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` ### Validation A minimal test file covering pass, skip, a flaky test that passes on rerun, a consistent failure with reruns, and an expected failure, run with `--reruns=2 --junit-xml-reruns`, serially and with `-n 2`, under pytest 7.3.2 (requirements-ci pin), 9.1.1 and 9.2.0. pytest-rerunfailures 14.0 and pytest-xdist 3.3.1 are the CI versions. In all six configurations the testcase/rerun/skipped/failure elements of the rerun XML match those the unmodified conftest produces under 9.1.1. Unmodified conftest under 9.2.0 crashes with the KeyError above. ``` PYTHONPATH=<overlay with pytest==$V pytest-rerunfailures==14.0 pytest-xdist==3.3.1> python -m pytest -q -p no:cacheprovider test_mini.py --reruns=2 [-n 2] --junit-xml-reruns=out/r.xml ``` Real test file with each pytest version: 251 passed and 251 testcases in the XML, no INTERNALERROR. The same command with the old conftest on 9.2.0 crashes after the first test. ``` cd test && PYTHONPATH=<overlay pytest==$V> python -m pytest -q -p no:cacheprovider test_pytree.py --reruns=2 -x --junit-xml-reruns=/tmp/rr/r.xml ``` The existing golden fixture `test/junit_xml_testdata/pytest_suite.py` (13 outcome shapes, normalized the same way `TestJunitXml` in `test/test_testing.py` does): - pytest 7.3.2: the new conftest output matches the committed golden `expected/pytest.xml`, which was recorded with pytest 7.3.2. - pytest 9.1.1: the new conftest output is identical to the old conftest's. - pytest 9.2.0: the new conftest output is identical to the old conftest's output under 9.1.1. The old conftest crashes with 81 INTERNALERRORs. The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above. `lintrunner test/conftest.py` is clean. <details> <summary>Agent Worklog</summary> # Worklog - 2026-10-28: Diffed pytest 9.1.1 and 9.2.0 `_pytest/junitxml.py`. `node_reporters` is now keyed by a `NodeId` dataclass (`report.id`); `finalize` pops `(report.id, workernode)`. conftest's copied `node_reporter` used string nodeids, so it fails at the first teardown, not only on reruns. - Reproduced with a minimal test file under overlays of pytest 7.3.2/9.1.1/9.2.0 on the job venv's torch. - Fix: delegate to `super().node_reporter` and set `__class__ = _NodeReporterReruns`. The XML matches the old behavior under all three versions, serial and with xdist. `test_pytree.py` passes under all three. lintrunner is clean. - Golden fixture junit_xml_testdata/pytest_suite.py: new==golden on 7.3.2, new==old on 9.1.1, new on 9.2.0 == old on 9.1.1. - 2026-10-29: (superseded) C1 test change moved to its own PR, see below. - 2026-10-29: split the C1 test change into job 20261029-pytorch-adhoc-7dcc5b (new PR below this one); this branch now sits on ptq/20261029-pytorch-adhoc-7dcc5b. Counts test passes on 9.2.0 with this fix. Not pushed. - 2026-10-29: now on the refactor 7879242; this PR moves the version skip onto the goldens and runs the counts (plus an INTERNALERROR check) on every version. Commit d334d9d. 9.2.0: counts pass with the fix, fail without. - 2026-10-29: shrank the test change: setUpClass unchanged except it records the version-mismatch reason (golden_skip) instead of raising, and keeps proc output; goldens skip on it; counts add an INTERNALERROR check. Commit 980d40eddfd. 7.3.2 all pass; 9.2.0 counts pass (fail without the conftest fix), goldens skip. - 2026-10-29: consolidated (Edward OK): pytorch#202597 closed, this PR retargeted to main, single commit de4b8db pushed, body Test section updated. - 2026-10-29: automated review flagged the pytest==9.1.1 pin from pytorch#202385 in install_inductor_benchmark_deps.sh as stale. Rebased onto origin/main 92264e2 and removed the pin (exact revert of pytorch#202385). TestJunitXml: 9.1.1 venv and 9.2.0 overlay pass (goldens skip); the 7.3.2 golden diffs I saw were my overlay run missing the repo-root pytest.ini; the PR-review agent confirmed old and new conftest match the goldens on 7.3.2 run in place. Not pushed. - 2026-10-30: Edward approved; pushed 1d11f93 via git (ssh). PR body not yet regenerated: gh on devgpu013 is logged out (~/.config/gh/hosts.yml emptied 2026-10-30 06:20). Body regenerated with ptq pr on 2026-10-30 after gh re-auth. - 2026-10-30: automated review of 1d11f93: without pytest installed, TestJunitXml errored (subprocess ran, no XML) instead of skipping. setUpClass now raises SkipTest first when pytest is missing. Verified with _junit_provenance patched to "pytest missing" (class skipped, subprocess not run); 9.1.1 venv and 9.2.0 overlay unchanged; lint clean. - 2026-10-30: per Edward, replaced the provenance-string checks: setUpClass skips when the child stderr has "No module named pytest" (no XML), and the counts test probes `import pytest_rerunfailures` with the child env. Note: earlier PYTHONPATH-overlay runs of TestJunitXml only changed the parent; the child drops PYTHONPATH and used the venv pytest 9.1.1. Re-verified with symlinked throwaway venvs: 9.2.0 counts pass (fail with origin/main conftest), 7.3.2 all pass, no pytest -> class skipped, no rerunfailures -> all skip. - 2026-10-30: replaced the stderr match and import probe with one child probe (_junit_child_versions, JSON of pytest/rerunfailures versions under _JUNIT_CHILD_ENV): it drives the class skip, has_rerunfailures, and the golden provenance (fixes parent/child mismatch under PYTHONPATH). Child env also drops PYTEST_PLUGINS/PYTEST_DISABLE_PLUGIN_AUTOLOAD. Verified: no pytest -> class skip; no rerunfailures -> 3 skips; 9.2.0 counts pass (fail with origin/main conftest); 7.3.2 all pass; job venv with PYTHONPATH=ov-7.3.2 or PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 -> OK. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202390 Approved by: https://github.com/nWEIdia, https://github.com/atalman, https://github.com/huydhn, https://github.com/jeanschmidt (cherry picked from commit 15e3725) Co-authored-by: Edward Z. Yang <[email protected]>
…est 9.2 (pytorch#202390) (#3935) ## Human Note I tried getting rid of the custom class entirely but Claude persuaded me it was useful. So we're just going to subclass from pytest so we can track upstream more easily. ## Agent Report ### Problem With pytest 9.2.0, any test run that writes `--junit-xml-reruns` (every CI test shard) aborts with an INTERNALERROR at the first test's teardown: ``` File "test/conftest.py", line 254, in pytest_runtest_logreport super().pytest_runtest_logreport(report) File "_pytest/junitxml.py", line 544, in finalize reporter = self.node_reporters.pop((node_id, workernode)) KeyError: (NodeId(path='test/test_pytree.py', names=('TestGenericPytree', 'test_aligned_public_apis'), params=None), None) ``` ### Root cause `LogXMLReruns.node_reporter` was a copy of pytest's `LogXML.node_reporter`. The copy only differed in building a `_NodeReporterReruns` and stored reporters under `(report.nodeid, workernode)`, with `nodeid` as a string. pytest 9.2 keys `node_reporters` by a new `NodeId` dataclass (`report.id`), and `LogXML.finalize` pops with that key. A `NodeId` never equals a string, so the pop fails. ### Fix Call `super().node_reporter(report)` so pytest builds the key and the reporter in whatever form that version uses, check that `_NodeReporterReruns` subclasses the returned type, then set the reporter's `__class__` to `_NodeReporterReruns`. The class docstring now says it may only override methods, not add state or change how instance data is represented. The subclass only overrides output methods (`_prepare_content`, `_write_content`, `append_skipped`) and adds no state, so switching the class in place is safe, and it removes the copy of pytest internals that went stale. I also added a docstring to `_NodeReporterReruns` explaining why it exists. pytest.ini sets `junit_logging_reruns = all`, and with the stock `_NodeReporter` every testcase, including passing tests that print nothing, gets a headed `<system-out>` and `<system-err>` element (skipped tests get both twice). The subclass writes captured output raw and omits empty streams. Regenerating the goldens without the subclass shows exactly that difference. The other option, branching on the pytest version to build the right key type, would keep the copy and break again the next time pytest changes the key. This also reverts pytorch#202385, which pinned `pytest==9.1.1` in the inductor-benchmarks images as a stopgap for this crash (TorchBench's requirements pull in an unpinned pytest). The other pytest 9.2 fixes still open shouldn't affect those images: pytorch#202406 (`--subprocess` test ids) only matters for the few test modules that `run_test.py` runs with `--subprocess`, which are CUDA-init and distributed tests the inductor configs don't run, and pytorch#202412 only restores the teardown part of the RERUNS terminal summary. ### Test `TestJunitXml` (test/test_testing.py) used to skip on every pytest version except the goldens' (the CI pins), so no test could see this crash. `setUpClass` now records that skip reason instead of raising and still runs the fixture suite; only the exact golden comparisons skip on other versions. The tag counts move out of `test_pytest_outcome_shapes` into `test_pytest_outcome_counts`, which runs on every version and also checks for INTERNALERROR. On pytest 9.2.0 the counts test passes with this change and fails without it; on 7.3.2 (the CI pin) all three tests pass. #### Where the versions come from Running the fixture suite on every version means `setUpClass` now depends on the environment in ways the old blanket skip hid, so the version checks have to describe the process that actually runs the suite. That process is a child (`sys.executable -m pytest`) with `PYTHONPATH` removed, so the parent's view can be wrong. Asking the parent with `importlib.metadata` would mean: - With pytest only on the parent's `PYTHONPATH`, the parent sees pytest, the child doesn't, writes no XML, and `setUpClass` raises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance). - With a different pytest on the parent's `PYTHONPATH`, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail. So `setUpClass` first runs a small probe, `_junit_child_versions()`, in the child's interpreter and environment: it prints the pytest and pytest-rerunfailures versions (or null) as JSON via `importlib.metadata`, without importing torch. That one result decides all three things: the class skips when pytest is missing, the counts test skips when pytest-rerunfailures is missing, and the golden header is built from it. The probe costs about 60 ms once per class, next to roughly 3.5 s for the fixture suite run the class already does. The alternatives were matching `No module named pytest` in the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing the `plugins:` line from pytest's console header (fragile, and only saves those 60 ms). The child also drops `PYTEST_PLUGINS` and `PYTEST_DISABLE_PLUGIN_AUTOLOAD`, as it already drops `PYTEST_ADDOPTS`, so it loads the installed plugins as CI does; with autoload off, pytest-rerunfailures was importable but never loaded and the counts were wrong. Checked in throwaway environments that really have each version (a `PYTHONPATH` overlay only changes the parent): | Child environment | Result | |---|---| | no pytest | class skipped | | pytest 9.1.1, no pytest-rerunfailures | all three skip | | pytest 9.2.0 + pytest-rerunfailures 14.0 | counts pass, goldens skip; counts fail with the old conftest | | pytest 7.3.2 + pytest-rerunfailures 14.0 | all three pass | | job venv with pytest 7.3.2 on the parent's `PYTHONPATH`, or `PYTEST_DISABLE_PLUGIN_AUTOLOAD=1` | counts pass, goldens skip | ``` cd test && CUDA_VISIBLE_DEVICES= python test_testing.py -k TestJunitXml ``` ### Validation A minimal test file covering pass, skip, a flaky test that passes on rerun, a consistent failure with reruns, and an expected failure, run with `--reruns=2 --junit-xml-reruns`, serially and with `-n 2`, under pytest 7.3.2 (requirements-ci pin), 9.1.1 and 9.2.0. pytest-rerunfailures 14.0 and pytest-xdist 3.3.1 are the CI versions. In all six configurations the testcase/rerun/skipped/failure elements of the rerun XML match those the unmodified conftest produces under 9.1.1. Unmodified conftest under 9.2.0 crashes with the KeyError above. ``` PYTHONPATH=<overlay with pytest==$V pytest-rerunfailures==14.0 pytest-xdist==3.3.1> python -m pytest -q -p no:cacheprovider test_mini.py --reruns=2 [-n 2] --junit-xml-reruns=out/r.xml ``` Real test file with each pytest version: 251 passed and 251 testcases in the XML, no INTERNALERROR. The same command with the old conftest on 9.2.0 crashes after the first test. ``` cd test && PYTHONPATH=<overlay pytest==$V> python -m pytest -q -p no:cacheprovider test_pytree.py --reruns=2 -x --junit-xml-reruns=/tmp/rr/r.xml ``` The existing golden fixture `test/junit_xml_testdata/pytest_suite.py` (13 outcome shapes, normalized the same way `TestJunitXml` in `test/test_testing.py` does): - pytest 7.3.2: the new conftest output matches the committed golden `expected/pytest.xml`, which was recorded with pytest 7.3.2. - pytest 9.1.1: the new conftest output is identical to the old conftest's. - pytest 9.2.0: the new conftest output is identical to the old conftest's output under 9.1.1. The old conftest crashes with 81 INTERNALERRORs. The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above. `lintrunner test/conftest.py` is clean. <details> <summary>Agent Worklog</summary> # Worklog - 2026-10-28: Diffed pytest 9.1.1 and 9.2.0 `_pytest/junitxml.py`. `node_reporters` is now keyed by a `NodeId` dataclass (`report.id`); `finalize` pops `(report.id, workernode)`. conftest's copied `node_reporter` used string nodeids, so it fails at the first teardown, not only on reruns. - Reproduced with a minimal test file under overlays of pytest 7.3.2/9.1.1/9.2.0 on the job venv's torch. - Fix: delegate to `super().node_reporter` and set `__class__ = _NodeReporterReruns`. The XML matches the old behavior under all three versions, serial and with xdist. `test_pytree.py` passes under all three. lintrunner is clean. - Golden fixture junit_xml_testdata/pytest_suite.py: new==golden on 7.3.2, new==old on 9.1.1, new on 9.2.0 == old on 9.1.1. - 2026-10-29: (superseded) C1 test change moved to its own PR, see below. - 2026-10-29: split the C1 test change into job 20261029-pytorch-adhoc-7dcc5b (new PR below this one); this branch now sits on ptq/20261029-pytorch-adhoc-7dcc5b. Counts test passes on 9.2.0 with this fix. Not pushed. - 2026-10-29: now on the refactor 7879242; this PR moves the version skip onto the goldens and runs the counts (plus an INTERNALERROR check) on every version. Commit d334d9d. 9.2.0: counts pass with the fix, fail without. - 2026-10-29: shrank the test change: setUpClass unchanged except it records the version-mismatch reason (golden_skip) instead of raising, and keeps proc output; goldens skip on it; counts add an INTERNALERROR check. Commit 980d40eddfd. 7.3.2 all pass; 9.2.0 counts pass (fail without the conftest fix), goldens skip. - 2026-10-29: consolidated (Edward OK): pytorch#202597 closed, this PR retargeted to main, single commit de4b8db pushed, body Test section updated. - 2026-10-29: automated review flagged the pytest==9.1.1 pin from pytorch#202385 in install_inductor_benchmark_deps.sh as stale. Rebased onto origin/main 92264e2 and removed the pin (exact revert of pytorch#202385). TestJunitXml: 9.1.1 venv and 9.2.0 overlay pass (goldens skip); the 7.3.2 golden diffs I saw were my overlay run missing the repo-root pytest.ini; the PR-review agent confirmed old and new conftest match the goldens on 7.3.2 run in place. Not pushed. - 2026-10-30: Edward approved; pushed 1d11f93 via git (ssh). PR body not yet regenerated: gh on devgpu013 is logged out (~/.config/gh/hosts.yml emptied 2026-10-30 06:20). Body regenerated with ptq pr on 2026-10-30 after gh re-auth. - 2026-10-30: automated review of 1d11f93: without pytest installed, TestJunitXml errored (subprocess ran, no XML) instead of skipping. setUpClass now raises SkipTest first when pytest is missing. Verified with _junit_provenance patched to "pytest missing" (class skipped, subprocess not run); 9.1.1 venv and 9.2.0 overlay unchanged; lint clean. - 2026-10-30: per Edward, replaced the provenance-string checks: setUpClass skips when the child stderr has "No module named pytest" (no XML), and the counts test probes `import pytest_rerunfailures` with the child env. Note: earlier PYTHONPATH-overlay runs of TestJunitXml only changed the parent; the child drops PYTHONPATH and used the venv pytest 9.1.1. Re-verified with symlinked throwaway venvs: 9.2.0 counts pass (fail with origin/main conftest), 7.3.2 all pass, no pytest -> class skipped, no rerunfailures -> all skip. - 2026-10-30: replaced the stderr match and import probe with one child probe (_junit_child_versions, JSON of pytest/rerunfailures versions under _JUNIT_CHILD_ENV): it drives the class skip, has_rerunfailures, and the golden provenance (fixes parent/child mismatch under PYTHONPATH). Child env also drops PYTEST_PLUGINS/PYTEST_DISABLE_PLUGIN_AUTOLOAD. Verified: no pytest -> class skip; no rerunfailures -> 3 skips; 9.2.0 counts pass (fail with origin/main conftest); 7.3.2 all pass; job venv with PYTHONPATH=ov-7.3.2 or PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 -> OK. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202390 Approved by: https://github.com/nWEIdia, https://github.com/atalman, https://github.com/huydhn, https://github.com/jeanschmidt (cherry picked from commit 15e3725) Co-authored-by: Edward Z. Yang <[email protected]>
Human Note
pytest 9.2.0 breaks inductor-periodic, pin the last known working version
Agent Report
Problem
Since pytest 9.2.0 was released (2026-10-27), every job on a
*-inductor-benchmarksCI image (inductor-periodicbenchmarks-cpu-test inductor_avx2, inductorinductor-cpu-testamx/aoti_fallback,inductor-test-cuda132cpp_wrapper/distributed) aborts its pytest session the first time a test is rerun:The test HUD names is whichever test happened to be running at the time.
Root cause
requirements-ci.txtpinspytest==7.3.2, butinstall_inductor_benchmark_deps.shruns TorchBench'sinstall.py, whoserequirements.txtlists an unpinnedpytest(andpytest-benchmark). The benchmarks images therefore carry whatever pytest is newest when the image is built: 9.1.1 in the last green runs, 9.2.0 after the images were rebuilt on 2026-10-28. In pytest 9.2.0,LogXML.finalizepops reporters by aNodeIdkey, whileLogXMLReruns.node_reporterintest/conftest.pystores them under the string nodeid, so the pop fails for rerun reports.Fix
Reinstall
pytest==9.1.1after the TorchBench/HuggingFace/timm installs. That restores the exact version the benchmarks images had while green. Pinning to the repo-wide 7.3.2 instead is not an option:pytest-benchmark5.3.0, which TorchBench installs, requires pytest>=8.1. Making the conftest override compatible with pytest 9.2 is a separate follow-up.Validation
bash -nand shellcheck lint on the changed script.pytest-9.1.1, and every failing run reportspytest-9.2.0together with the junitxml KeyError.Agent Worklog
Worklog
e5ceb2had pytest-9.1.1. TorchBench pin c5ea24d7 requirements.txt lists an unpinnedpytest. No fix PR or tracking issue existed.pytest==9.1.1in.ci/docker/common/install_inductor_benchmark_deps.shafter the benchmark installs. Lint is clean.This PR was generated by ptq with human review.