Repository navigation
Conversation
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/202390
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f393be6 with merge base 92264e2 ( 🟡 GREEN LIGHT - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
af32772 to
65b55a9
Compare
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: No LLM was invoked during this run. |
65b55a9 to
cf0c17c
Compare
Withdrawn: the automated review of cf0c17c found nothing blocking.
45e7d1c to
7879242
Compare
cf0c17c to
d334d9d
Compare
## 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_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 #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: #202412 Approved by: https://github.com/Skylion007
…ersion pin to 0.0.3 (pytorch#201122) This PR re-enables origami for all Rocm versions and pins rocm-origami pypi package version to 0.0.3 Before submitting, please review: - [PR lifecycle](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#pr-lifecycle) in the contributing guide - [AI-Assisted Development](https://github.com/pytorch/pytorch/blob/main/AI_POLICY.md) policy Go through the following checklist - [x] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation (if applicable) - [x] Included benchmark results (for PRs impacting perf) --- ## Linked issue or supporting maintainer <!-- Keep the one line that applies and delete the others. Link an issue labeled "actionable", or name the maintainer who agreed to this change beforehand. PRs with neither will be automatically closed, unless the author has write access to the repo. --> Supported by @jeffdaily <!-- If this change breaks backward compatibility, describe the impact and migration path. Otherwise, write "No". --> ## Summary (human written only) rocm-origami 0.0.2 does not match the origami library API in ROCm 10.0+, so pytorch#193843 disabled origami on ROCm >= 10.0. This PR pins rocm-origami to 0.0.3, which matches it, and replaces the ROCm version cutoff with a package-version gate: on ROCm >= 10.0, origami is used only when the installed rocm-origami is >= 0.0.3 (an older or unparsable version logs a warning and disables origami). `TestOrigamiPackageVersionGate` covers the gate, and `TestOrigami` skips when the gate has disabled origami. Validated on MI300X (ROCm 10.1) with rocm-origami 0.0.3 (origami active, all tests pass) and 0.0.2 (gate disables origami, `TestOrigami` skips). Note that `.ci/docker/ci_commit_pins/rocm-origami.txt` rebuilds the CI images, so this should merge only after pytorch#202390. ## Tests and Benchmarks. After re-enabling origami, gemm kernel latency was within the 5% tolerance compared to max-autotune for all shapes in the unit test and compilation time was <img width="655" height="668" alt="image" src="https://github.com/user-attachments/assets/89b6310b-b22d-46b5-ad23-f2fd2d16df4c" /> <img width="638" height="262" alt="image" src="https://github.com/user-attachments/assets/6e2677a6-27f6-42ff-9646-4f4474f07650" /> Pull Request resolved: pytorch#201122 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…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
…ersion pin to 0.0.3 (pytorch#201122) This PR re-enables origami for all Rocm versions and pins rocm-origami pypi package version to 0.0.3 Before submitting, please review: - [PR lifecycle](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#pr-lifecycle) in the contributing guide - [AI-Assisted Development](https://github.com/pytorch/pytorch/blob/main/AI_POLICY.md) policy Go through the following checklist - [x] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation (if applicable) - [x] Included benchmark results (for PRs impacting perf) --- ## Linked issue or supporting maintainer <!-- Keep the one line that applies and delete the others. Link an issue labeled "actionable", or name the maintainer who agreed to this change beforehand. PRs with neither will be automatically closed, unless the author has write access to the repo. --> Supported by @jeffdaily <!-- If this change breaks backward compatibility, describe the impact and migration path. Otherwise, write "No". --> ## Summary (human written only) rocm-origami 0.0.2 does not match the origami library API in ROCm 10.0+, so pytorch#193843 disabled origami on ROCm >= 10.0. This PR pins rocm-origami to 0.0.3, which matches it, and replaces the ROCm version cutoff with a package-version gate: on ROCm >= 10.0, origami is used only when the installed rocm-origami is >= 0.0.3 (an older or unparsable version logs a warning and disables origami). `TestOrigamiPackageVersionGate` covers the gate, and `TestOrigami` skips when the gate has disabled origami. Validated on MI300X (ROCm 10.1) with rocm-origami 0.0.3 (origami active, all tests pass) and 0.0.2 (gate disables origami, `TestOrigami` skips). Note that `.ci/docker/ci_commit_pins/rocm-origami.txt` rebuilds the CI images, so this should merge only after pytorch#202390. ## Tests and Benchmarks. After re-enabling origami, gemm kernel latency was within the 5% tolerance compared to max-autotune for all shapes in the unit test and compilation time was <img width="655" height="668" alt="image" src="https://github.com/user-attachments/assets/89b6310b-b22d-46b5-ad23-f2fd2d16df4c" /> <img width="638" height="262" alt="image" src="https://github.com/user-attachments/assets/6e2677a6-27f6-42ff-9646-4f4474f07650" /> Pull Request resolved: pytorch#201122 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…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 pytest 9.2 keys LogXML.node_reporters by a NodeId object instead of the string nodeid. LogXMLReruns.node_reporter kept a copy of the old pytest code that stored reporters under the string key, so LogXML.finalize fails with KeyError at the first test's teardown and every test module aborts after one case when --junit-xml-reruns is used. Delegate to LogXML.node_reporter so pytest builds the key, then switch the reporter's class to _NodeReporterReruns. TestJunitXml now runs the fixture suite on every pytest version; only the exact golden comparisons skip when the versions differ from the goldens'. A new test_pytest_outcome_counts test checks the XML tag counts and that no INTERNALERROR occurred, so this crash is caught on any pytest version. The inductor benchmark pytest pin that upstream reverts was never added to this branch, so that part is not included. Upstream: pytorch#202390 (cherry picked from commit 15e3725)
Pytest 9.2 crashed when the JUnit reporter used a different key from pytest. Redis 8.2.0 raised a BytesWarning on import under python -bb. Merge main at 579ecc5 to use pytest's reporter keys (pytorch#202390) and the upstream CI images that cap Redis below 8.2.0 (pytorch#206270). This keeps the load deduplication patch unchanged. Test Plan The affected jobs passed on the merged main commit in https://github.com/pytorch/pytorch/actions/runs/46101078121. The staged tree matched a replay of the original patch on that commit. Syntax and PR diff checks passed. ```sh git diff --cached --check MERGE_HEAD git diff --cached --exit-code MERGE_HEAD -- .ci/docker test/conftest.py test/test_testing.py git diff --cached MERGE_HEAD | git patch-id --stable git diff HEAD^ HEAD | git patch-id --stable python -m py_compile torch/_inductor/dependencies.py test/conftest.py ``` Local lint and the CPU and CUDA suites did not run. This checkout lacks lintrunner and a PyTorch build. Authored with an AI assistant.
…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
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:Root cause
LogXMLReruns.node_reporterwas a copy of pytest'sLogXML.node_reporter. The copy only differed in building a_NodeReporterRerunsand stored reporters under(report.nodeid, workernode), withnodeidas a string. pytest 9.2 keysnode_reportersby a newNodeIddataclass (report.id), andLogXML.finalizepops with that key. ANodeIdnever 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_NodeReporterRerunssubclasses 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_NodeReporterRerunsexplaining why it exists. pytest.ini setsjunit_logging_reruns = all, and with the stock_NodeReporterevery 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.1in 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 (--subprocesstest ids) only matters for the few test modules thatrun_test.pyruns 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.setUpClassnow 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 oftest_pytest_outcome_shapesintotest_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
setUpClassnow 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) withPYTHONPATHremoved, so the parent's view can be wrong. Asking the parent withimportlib.metadatawould mean:PYTHONPATH, the parent sees pytest, the child doesn't, writes no XML, andsetUpClassraises instead of skipping (the case the automated review hit, where pytest is missing entirely, is the simplest instance).PYTHONPATH, the golden header check compares the goldens against one version while the child produces XML with another, and the golden tests fail.So
setUpClassfirst 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 viaimportlib.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 matchingNo module named pytestin the fixture run's stderr (covers only the missing-pytest case and leaves the golden mismatch) or parsing theplugins:line from pytest's console header (fragile, and only saves those 60 ms).The child also drops
PYTEST_PLUGINSandPYTEST_DISABLE_PLUGIN_AUTOLOAD, as it already dropsPYTEST_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
PYTHONPATHoverlay only changes the parent):PYTHONPATH, orPYTEST_DISABLE_PLUGIN_AUTOLOAD=1Validation
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.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.
The existing golden fixture
test/junit_xml_testdata/pytest_suite.py(13 outcome shapes, normalized the same wayTestJunitXmlintest/test_testing.pydoes):expected/pytest.xml, which was recorded with pytest 7.3.2.The change was reviewed by two fresh agents (correctness and quality) before this update; their findings are addressed above.
lintrunner test/conftest.pyis clean.Agent Worklog
Worklog
_pytest/junitxml.py.node_reportersis now keyed by aNodeIddataclass (report.id);finalizepops(report.id, workernode). conftest's copiednode_reporterused string nodeids, so it fails at the first teardown, not only on reruns.super().node_reporterand set__class__ = _NodeReporterReruns. The XML matches the old behavior under all three versions, serial and with xdist.test_pytree.pypasses under all three. lintrunner is clean.import pytest_rerunfailureswith 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.This PR was generated by ptq with human review.