Skip to content

Keep approx failure details for zero timedeltas - #15165

Open
muneikh wants to merge 2 commits into
pytest-dev:mainfrom
muneikh:fix-zero-timedelta-approx-diagnostics
Open

muneikh wants to merge 2 commits into
pytest-dev:mainfrom
muneikh:fix-zero-timedelta-approx-diagnostics

Conversation

@muneikh

@muneikh muneikh commented Oct 11, 2026

Copy link
Copy Markdown

Keep approx failure details for zero timedeltas

When an obtained duration in a sequence is zero, a failing approx assertion
loses its mismatch table because the relative-difference calculation divides
by timedelta(0). In mappings, an expected zero duration is skipped in that
calculation, which can understate the maximum relative difference.

The existing numeric zero guards now recognize timedelta(0) too. This keeps
the duration mismatch table and reports an infinite relative difference when
its denominator is zero. The regression cases include a second finite
difference to check that it cannot replace the infinite result.

Validation: the two new regression cases fail on the original source; the
approx and assertion modules pass (388 tests). The complete Python 3.13 tox
environment passes (4,694 passed, 51 skipped, 15 xfailed, 5 xpassed). The pinned
pre-commit checks on the changed files pass, including mypy.

A zero timedelta does not compare equal to numeric zero. Include it in the
relative-difference guards so failing duration sequences keep their mismatch
table and mappings report an infinite relative difference.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 11, 2026
@muneikh
muneikh marked this pull request as ready for review October 11, 2026 14:34
@0xamlab

This comment was marked as low quality.

This branch has not been deployed

No deployments
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.

2 participants