Skip to content

Preserve supplied XML attributes during lazy statistics reads - #185

Open
sunxiuguo wants to merge 1 commit into
weiwei:masterfrom
sunxiuguo:work/preserve-lazy-statistics-20261023
Open

sunxiuguo wants to merge 1 commit into
weiwei:masterfrom
sunxiuguo:work/preserve-lazy-statistics-20261023

Conversation

@sunxiuguo

Copy link
Copy Markdown

Problem

Related to #141. Loading a report and reading an existing suite duration already preserves the producer's value. The remaining problem is an ordinary read of a missing numeric summary field: report.tests, for example, calls update_statistics() on the live tree and replaces descendant durations.

With a suite annotated time="10" and two parallel testcases with times 8 and 9, reading report.tests changes the suite time to 17. Writing the document then persists that unintended change.

Change

Calculate missing attributes on a shallow wrapper copy with an independent XML subtree, then copy only attributes absent from the original root. Supplied XML values and descendant annotations remain unchanged. Copying all missing calculated root attributes also preserves custom descriptor metadata.

Explicit update_statistics() and testcase mutation methods still recalculate as before. A missing root duration still uses accumulated testcase time (17 in this example), not inferred wall-clock time. This does not implement the separate accumulated-time API discussed in #141.

Validation

Python 3.12.14 on Linux, synthetic fixtures only:

  • Full suite with lxml 6.0.2: 152 passed, 2 skipped.
  • Full suite with ElementTree: 151 passed, 3 skipped.
  • Ruff 0.15.12 check and format check passed.
  • Independent automated review and runtime checks covered nested suites, xunit2's omitted skipped field, non-copyable subclass state, custom numeric/string attributes, explicit recalculation, and XML write/read preservation.

The lxml run skips a Windows-only path test (its existing skip message says "lxml not installed") and the stdlib-only backend assertion. The ElementTree run additionally skips the lxml-specific parser case. Hosted CI has not yet been observed.

Tradeoff

Lazy calculation now copies the XML subtree once when summary fields are missing. A single synthetic 100,000-case measurement was 0.388s before vs 0.496s after, with peak RSS 75,776 vs 138,644 KiB (about 61.4 MiB extra). This is not a stable benchmark, and large reports can incur material extra memory. A pure statistics calculator could avoid that copy but would be a broader refactor.

AI-assisted implementation and independent automated review; no claim of human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant