Skip to content

fix: avoid duplicate report rows for pytest 9 subtests - #1076

Open
xuanshen666 wants to merge 1 commit into
pytest-dev:masterfrom
xuanshen666:fix-981-subtest-duplicate-rows
Open

xuanshen666 wants to merge 1 commit into
pytest-dev:masterfrom
xuanshen666:fix-981-subtest-duplicate-rows

Conversation

@xuanshen666

Copy link
Copy Markdown

What

When a test uses the new subtests fixture from pytest 9 and has mixed pass/fail subtest outcomes, pytest-html generates two rows for the same test (one "Passed" and one "Failed").

Why

Each subtest emits its own pytest_runtest_logreport with when="call" and the same nodeid. pytest-html stores these per-subtest reports as separate result rows instead of collapsing them into the parent test's single row.

How

In BaseReport.pytest_runtest_logreport, skip subtest reports (identified by the context attribute). The parent test's own call report already contains the full subtest details, so a single row is still produced with the correct outcome and log.

Verification

  • Added test_subtests_single_row to testing/test_unit.py (skipped on pytest < 9).
  • Before the fix the test produced 2 rows (Passed, Failed); after the fix it produces 1 row (Failed).
  • pytest testing/test_unit.py passes (8 passed).

Closes #981

@xuanshen666

Copy link
Copy Markdown
Author

Note: the failing pre-commit.ci check is the djlint hook on src/pytest_html/resources/index.jinja2 (H024/H056/H057/H043). This PR does not touch that file, so the failure is pre-existing on master — likely djlint version drift, since those rules are not in the [tool.djlint] ignore list. The files changed here (src/pytest_html/basereport.py, testing/test_unit.py) pass black, flake8, mypy, and reorder-python-imports.

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.

pytest 9.0: subtests feature causes the test to be reported twice - both failed and passed

1 participant