Repository navigation
Conversation
test/conftest.py's RERUNS section (#86831) prints why each rerun attempt failed, since pytest-rerunfailures itself only lists reruns. It did so through four private TerminalReporter methods (`_getcrashline`, `_getfailureheadline`, `_outrep_summary`, `_handle_teardown_sections`). pytest 9.2 changed `_handle_teardown_sections` to take a `NodeId`, so the teardown part silently printed nothing. This builds the same output from public API: each rerun report's `head_line`, `toterminal()` (onto `config.get_terminal_writer()`) and `sections`, filtered by `--show-capture` like pytest's FAILURES section. Two parts are dropped: - the `--tb=line` branch (one crash line per attempt): CI runs with `--tb=native`, or `--tb=long` with `--showlocals`; - the teardown sections: they were looked up by node id, so they printed the teardown output of every attempt of the test (including the one that passed) under each failed attempt. Test plan: a flaky test that prints in call and teardown, a test that fails all attempts, and a passing test, run with `--reruns=1` under pytest 7.3.2, 9.1.1 and 9.2.0, with `--tb=native` and `--tb=long --color=yes --showlocals`. The new RERUNS section is identical to the old one except for the dropped teardown sections. ``` cd test && PYTHONPATH=<pytest==$V overlay> python -m pytest -p no:cacheprovider zz_scratch_reruns.py --reruns=1 ``` Authored with an AI assistant (Claude).
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202412
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 Unclassified FailuresAs of commit 7955b35 with merge base 21d72b9 ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
mergedog handoffNote This PR is being shepherded by mergedog, an automation tool run by a maintainer. It watches CI and may push fixes; the PR author does not need to act unless a maintainer asks. All CI is green (or skipped). Ready for human review and Current PR head: Autonomous changes pushed
CI notes at handoffmergedog is treating these still-failing checks as unrelated/spurious. Please verify before merging:
Warning: mergedog's suppressed check list differs from the latest Dr. CI summary. Suppressed by mergedog but not marked unrelated by Dr. CI:
Latest Dr. CI summary## PR Status: in progress
A maintainer requested changes. Please address their feedback before the PR returns to maintainer review.
To become ready for review, the change must pass automated review and every maintainer comment must be addressed, either with a code change or a reply explaining why no change is needed. A fresh automated review checks that the feedback has been addressed. All CI must finish and Dr. CI must classify every failure as unrelated to your PR. Fix the failures it attributes to your PR (see status below in this comment). Workflows waiting for a maintainer to approve their run do not block this.
To minimize iteration time, feel free to run the pr-review skill from the repo locally. If you address comments without pushing, comment `@pytorchbot review` to re-run the automated review. To bypass automated review, please add the “no automated review” label.
<details><summary>🟡 <b>AUTOMATED REVIEW</b> - Changes requested:</summary><p>
The PR rebuilds the RERUNS section in test/conftest.py from public report fields [major] test/conftest.py:293 if config.option.tbstyle == "line": Then update the PR description, which lists this branch as dropped. During shepherding, the configured LLM was invoked 1 time. If any CI shows red, it judged that failure unrelated to this PR's changes — please verify below before merging. Session 1 — fix-CI (2026-10-29T14:42:46+00:00)
LLM transcript |
Address the automated review: with --tb=line, print one crash line per rerun attempt, as before, instead of the long traceback. The old branch called the private _getcrashline, which is str(rep.longrepr.reprcrash) with a fallback; use that public field directly. Test plan: a flaky test, a test that fails all attempts, a setup error and a pytest.fail() run with --reruns=1 --tb=line under pytest 7.3.2 and 9.2.0. The RERUNS section has one line per attempt, matching the old conftest except where the two pytest versions format reprcrash differently. Authored with an AI assistant (Claude).
There was a problem hiding this comment.
Automated review of 7955b35: nothing blocking; ready for human review.
The PR rebuilds the RERUNS section of test/conftest.py from public pytest report fields. Before, it called private TerminalReporter methods, and pytest 9.2 quietly broke that part so it printed nothing. The review found no issues and its Recommendation is Approve: the change only touches test-harness reporting, and its output matches the old code apart from the dropped teardown sections and two fallback differences.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
Withdrawn: the automated review of 7955b35 found nothing blocking.
|
@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 |
Merge failedReason: 2 jobs have failed, first few of them are: .github/workflows/trunk.yml, .github/workflows/tsan.yml Details for Dev Infra teamRaised by workflow job |
## 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
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: trunk, .github/workflows/tsan.yml Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…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 Claude removed the tb=line branch since it doesn't trigger in CI, and claims the teardown sections stuff never worked even on older pytest. I don't really have a bone in this fight. ## Agent Report test/conftest.py's RERUNS section (pytorch#86831) prints why each rerun attempt failed, since pytest-rerunfailures itself only lists reruns. It did so through four private TerminalReporter methods (`_getcrashline`, `_getfailureheadline`, `_outrep_summary`, `_handle_teardown_sections`). pytest 9.2 changed `_handle_teardown_sections` to take a `NodeId`, so the teardown part silently printed nothing. This builds the same output from public API: each rerun report's `head_line`, `toterminal()` (onto `config.get_terminal_writer()`) and `sections`, filtered by `--show-capture` like pytest's FAILURES section. With `--tb=line` it still prints one crash line per attempt, now from the public `rep.longrepr.reprcrash` (falling back to the start of `str(longrepr)`, as `_getcrashline` did, for a plain-string longrepr such as an xdist worker crash's). One part is dropped: the teardown sections. They were looked up by node id, so they printed the teardown output of every attempt of the test (including the one that passed) under each failed attempt. Test plan: a flaky test that prints in call and teardown, a test that fails all attempts, and a passing test, run with `--reruns=1` under pytest 7.3.2, 9.1.1 and 9.2.0, with `--tb=native` and `--tb=long --color=yes --showlocals`. The new RERUNS section is identical to the old one except for the dropped teardown sections. With `--tb=line` (adding a setup error and a `pytrace=False` failure) under 7.3.2 and 9.2.0, it prints one line per attempt, matching the old conftest except where the two pytest versions format `reprcrash` differently. ``` cd test && PYTHONPATH=<pytest==$V overlay> python -m pytest -p no:cacheprovider zz_scratch_reruns.py --reruns=1 ``` Authored with an AI assistant (Claude). <details> <summary>Agent Worklog</summary> - 2026-10-28: split out of pytorch#202390 (C). Verified on 7.3.2/9.1.1/9.2.0. - 2026-10-29: kept the `--tb=line` branch (automated review), via public `reprcrash`. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202412 Approved by: https://github.com/Skylion007
…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 Claude removed the tb=line branch since it doesn't trigger in CI, and claims the teardown sections stuff never worked even on older pytest. I don't really have a bone in this fight. ## Agent Report test/conftest.py's RERUNS section (pytorch#86831) prints why each rerun attempt failed, since pytest-rerunfailures itself only lists reruns. It did so through four private TerminalReporter methods (`_getcrashline`, `_getfailureheadline`, `_outrep_summary`, `_handle_teardown_sections`). pytest 9.2 changed `_handle_teardown_sections` to take a `NodeId`, so the teardown part silently printed nothing. This builds the same output from public API: each rerun report's `head_line`, `toterminal()` (onto `config.get_terminal_writer()`) and `sections`, filtered by `--show-capture` like pytest's FAILURES section. With `--tb=line` it still prints one crash line per attempt, now from the public `rep.longrepr.reprcrash` (falling back to the start of `str(longrepr)`, as `_getcrashline` did, for a plain-string longrepr such as an xdist worker crash's). One part is dropped: the teardown sections. They were looked up by node id, so they printed the teardown output of every attempt of the test (including the one that passed) under each failed attempt. Test plan: a flaky test that prints in call and teardown, a test that fails all attempts, and a passing test, run with `--reruns=1` under pytest 7.3.2, 9.1.1 and 9.2.0, with `--tb=native` and `--tb=long --color=yes --showlocals`. The new RERUNS section is identical to the old one except for the dropped teardown sections. With `--tb=line` (adding a setup error and a `pytrace=False` failure) under 7.3.2 and 9.2.0, it prints one line per attempt, matching the old conftest except where the two pytest versions format `reprcrash` differently. ``` cd test && PYTHONPATH=<pytest==$V overlay> python -m pytest -p no:cacheprovider zz_scratch_reruns.py --reruns=1 ``` Authored with an AI assistant (Claude). <details> <summary>Agent Worklog</summary> - 2026-10-28: split out of pytorch#202390 (C). Verified on 7.3.2/9.1.1/9.2.0. - 2026-10-29: kept the `--tb=line` branch (automated review), via public `reprcrash`. </details> --- *This PR was generated by [ptq](https://github.com/drisspg/pt_job_queue) with human review.* Pull Request resolved: pytorch#202412 Approved by: https://github.com/Skylion007
…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
Claude removed the tb=line branch since it doesn't trigger in CI, and claims the teardown sections stuff never worked even on older pytest. I don't really have a bone in this fight.
Agent Report
test/conftest.py's RERUNS section (#86831) prints why each rerun attempt
failed, since pytest-rerunfailures itself only lists reruns. It did so through
four private TerminalReporter methods (
_getcrashline,_getfailureheadline,_outrep_summary,_handle_teardown_sections). pytest 9.2 changed_handle_teardown_sectionsto take aNodeId, so the teardown part silentlyprinted nothing.
This builds the same output from public API: each rerun report's
head_line,toterminal()(ontoconfig.get_terminal_writer()) andsections, filtered by--show-capturelike pytest's FAILURES section. With--tb=lineit stillprints one crash line per attempt, now from the public
rep.longrepr.reprcrash(falling back to the start ofstr(longrepr), as_getcrashlinedid, for a plain-string longrepr such as an xdist workercrash's).
One part is dropped: the teardown sections. They were looked up by node id, so
they printed the teardown output of every attempt of the test (including the
one that passed) under each failed attempt.
Test plan: a flaky test that prints in call and teardown, a test that fails all
attempts, and a passing test, run with
--reruns=1under pytest 7.3.2, 9.1.1and 9.2.0, with
--tb=nativeand--tb=long --color=yes --showlocals. The newRERUNS section is identical to the old one except for the dropped teardown
sections. With
--tb=line(adding a setup error and apytrace=Falsefailure)under 7.3.2 and 9.2.0, it prints one line per attempt, matching the old
conftest except where the two pytest versions format
reprcrashdifferently.Authored with an AI assistant (Claude).
Agent Worklog
--tb=linebranch (automated review), via publicreprcrash.This PR was generated by ptq with human review.