Skip to content

Fix junitxml count for teardown errors#14501

Merged
nicoddemus merged 8 commits into
pytest-dev:mainfrom
puneetdixit200:junitxml-teardown-count
May 24, 2026
Merged

Fix junitxml count for teardown errors#14501
nicoddemus merged 8 commits into
pytest-dev:mainfrom
puneetdixit200:junitxml-teardown-count

Conversation

@puneetdixit200
Copy link
Copy Markdown
Contributor

@puneetdixit200 puneetdixit200 commented May 21, 2026

Fixes #3850

Summary

  • correct the JUnit XML tests count when a test passes during call but fails during teardown
  • assert in run_and_parse that the testsuite tests attribute matches the emitted <testcase> nodes
  • keep call-failure plus teardown-error as separate testcase nodes, while the pass-plus-teardown-error path stays one testcase node
  • add a changelog entry

Tests

  • .venv/bin/python -m pytest testing/test_junitxml.py -q
  • .venv/bin/pre-commit run --color never --files src/_pytest/junitxml.py testing/test_junitxml.py changelog/3850.bugfix.rst
  • git diff --check

AI assistance was used while iterating on the patch and tests. I reviewed the change and can explain it.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label May 21, 2026
Copy link
Copy Markdown
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, left some comments!

Comment thread testing/test_junitxml.py Outdated
Comment thread src/_pytest/junitxml.py Outdated
Puneet Dixit and others added 3 commits May 23, 2026 20:25
Use run_and_parse for the teardown regression and assert the testsuite count matches emitted testcase nodes. Keep the teardown-only adjustment only for the pass-plus-teardown-error case where both reports share a testcase node.

Co-authored-by: OpenAI GPT-5 <noreply@openai.com>
@puneetdixit200 puneetdixit200 force-pushed the junitxml-teardown-count branch from 2a63e72 to 549f134 Compare May 23, 2026 14:57
@puneetdixit200
Copy link
Copy Markdown
Contributor Author

Rebased onto current main to pick up the unittest skip fixture fix from #14505.

Verification run locally:

uv run --with-editable . --extra dev python -m pytest testing/test_junitxml.py testing/test_unittest.py::test_setup_inheritance_skipping testing/test_unittest.py::test_pdb_teardown_skipped_for_classes testing/test_debugging.py::TestPDB::test_pdb_unittest_skip -q --junitxml=/tmp/pytest-14501-after-rebase.xml
# 142 passed, 3 skipped

puneetdixit200 and others added 3 commits May 23, 2026 23:27
Rely on the shared run_and_parse testcase-count invariant instead of keeping a duplicate teardown regression with the same fixture shape.

Co-authored-by: OpenAI GPT-5 <noreply@openai.com>
@puneetdixit200
Copy link
Copy Markdown
Contributor Author

The current head addresses the review comments:

  • the new JUnit XML cases now go through run_and_parse
  • run_and_parse asserts the tests attribute against the emitted <testcase> nodes
  • the production branch has a comment pointing back to junit xml "tests" number seems wrong if only teardown fails #3850
  • the branch was rebased onto current main to pick up the unittest skip fixture fix

Latest local check after the rebase was 142 passed, 3 skipped for testing/test_junitxml.py plus the related unittest/debugging skip tests.

Copy link
Copy Markdown
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread changelog/3850.bugfix.rst Outdated
Comment thread testing/test_junitxml.py
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
@nicoddemus nicoddemus enabled auto-merge (squash) May 24, 2026 13:31
@nicoddemus nicoddemus merged commit e2dbcb2 into pytest-dev:main May 24, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

junit xml "tests" number seems wrong if only teardown fails

2 participants