Repository navigation
Conversation
Keep subtest reports out of the parent reporter cache and retain parent outcomes and inclusive durations. Include repeated contexts, unittest, teardown errors, output, and xdist regression coverage. Refs pytest-dev#13876. Co-authored-by: Codex <[email protected]>
Check subtest outcomes independently of their arrival order on Python 3.10. Clarify report indices and exercise per-report user property snapshots. Co-authored-by: Codex <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Subtests share their parent's node ID, so JUnit XML currently puts their outcomes in the parent's cached testcase. Passing subtests have no separate entries, and suite counts can disagree with the number of testcase elements. A local reproduction containing fixture and unittest subtests produced 5 testcase elements with
tests="13"; this patch produces 13 elements with the same suite count.Closes #13876.
Each
SubtestReportnow uses its own reporter outside the parent's setup/call/teardown cache. The testcase name combines the parent name, a report index, and the existing message/parameter description, for exampletest_parent [subtest 2] [check] (i=1). The index follows report arrival order, which can differ from execution order with deferred unittest reporting on Python 3.10. Repeated contexts remain distinct without changing collection IDs. Existing helpers handle outcome details, family-specific attributes, captured output, and properties.The parent and every subtest remain in the report. Parent outcomes are preserved, including independent assertions and teardown errors. A fixture parent can therefore count as a failure alongside its failed subtest; unittest currently emits a passing parent call after failed subtests. Each child records its own duration, while the parent retains its inclusive duration according to
junit_duration_report. Parent and child times overlap. The documentation explains these accounting choices, which are proposed for review.Local validation on macOS arm64 / CPython 3.10.21 and 3.13.15:
c9bf1edf9e0d388f3e7bebc88576e608ffbc40a4.python -m pytest testing/test_junitxml.py testing/test_subtests.py testing/test_unittest.py -q: 271 passed, 8 skipped on Python 3.10 and 270 passed, 9 skipped on Python 3.13. Eight skips require Twisted; the extra skip on 3.13 is asynctest compatibility. The original tests also passed withPYTHONWARNDEFAULTENCODING=1before the CI follow-up.pre-commit run --all-files --show-diff-on-failure: passed, including Ruff, mypy, spelling, and documentation code-block checks. Changed-file checks, including AUTHORS, andgit diff --checkalso passed.The CI run for the current head completed successfully across all configured Windows/Linux/macOS jobs. All 36 PR checks passed. The Linux Python 3.10 full-suite coverage job reported 4707 passed, 50 skipped, 13 xfailed, 7 xpassed, and 2 warnings.
Not run locally: the full pytest suite, other Python versions, Windows/Linux, full Sphinx build, manual Pyright/Pylint hooks, or CI consumer applications. The existing unittest integration supplies zero subtest durations. Existing xdist context deserialization applies repr again, so distributed parameter descriptions can differ from local ones; this patch preserves the received descriptions.
Prepared with Codex assistance for investigation, implementation, regression testing, and this description. The implementation commit includes a
Co-authored-byattribution.Co-authored-bytrailer.changelog/13876.improvement.rst.Cen Junyi(cjyhjy)to AUTHORS in alphabetical order.