Add datetime/timedelta support to pytest.approx (#8395)#14414
Open
hamza-mobeen wants to merge 2 commits intopytest-dev:mainfrom
Open
Add datetime/timedelta support to pytest.approx (#8395)#14414hamza-mobeen wants to merge 2 commits intopytest-dev:mainfrom
hamza-mobeen wants to merge 2 commits intopytest-dev:mainfrom
Conversation
b4ef81a to
23e7a5e
Compare
Closes pytest-dev#8395 Co-authored-by: Antigravity <antigravity@google.com>
2ea6f2f to
e720397
Compare
for more information, see https://pre-commit.ci
Author
|
Hi @RonnyPfannschmidt , |
Member
|
At first glance this looks good Im currently a bit stretched and hope to take a closer look next week |
Author
no problem thanks. |
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.
Closes #8395
Description
This PR introduces native support for comparing
datetime.datetimeanddatetime.timedeltaobjects usingpytest.approx().Following the guidelines discussed in #8395:
abs) must be provided as adatetime.timedeltaobject. We intentionally avoid providing default tolerances as time comparisons lack sane defaults.rel) are not supported for time comparisons and will raise aTypeErrorwith an informative message.nan_okis also explicitly rejected for time comparisons.ApproxTimedeltaas an internal helper class to manage this specific comparison logic.testing/python/approx.pyensuring there are no regressions with existing numeric approximation behavior.Usage Example
Example Test Coverage
Checklist
closes #XYZWto the PR description and/or commits (whereXYZWis the issue number).Co-authored-bycommit trailers.changelogdirectory, with a name like<ISSUE NUMBER>.<TYPE>.rst.AUTHORSin alphabetical order.