Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue30190

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:unittest's assertAlmostEqual improved error message
Type:enhancementStage:resolved
Components:Library (Lib)Versions:Python 3.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: ezio.melotti, giampaolo.rodola, michael.foord, rbcollins, rhettinger, serhiy.storchaka
Priority:normalKeywords:

Created on2017-04-27 20:12 bygiampaolo.rodola, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 1331mergedgiampaolo.rodola,2017-04-27 20:52
PR 1534mergedgiampaolo.rodola,2017-05-10 13:24
Messages (14)
msg292477 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-04-27 20:12
When comparing 2 numbers as "self.assertAlmostEqual(a, b, delta=1000)" the error message looks like this:    AssertionError: 27332885 != 27391120 within 1000 deltaEspecially when a and b are big numbers or differ a lot, it would be useful to see the absolute difference between the 2 numbers as in:    AssertionError: 27332885 != 27391120 within 1000 delta (58235 difference)
msg292482 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-04-27 20:53
PR:https://github.com/python/cpython/pull/1331/
msg292510 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-04-28 05:02
Is it worth to output a difference when the delta argument is not passed?Is it worth to output a signed difference rather than an absolute value?
msg292537 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-04-28 16:17
Thanks for chiming in.> Is it worth to output a difference when the delta argument is not passed?Yes, probably. I will change that.> Is it worth to output a signed difference rather than an absolute value?Mmmm probably not IMHO. Personally I never care about the position of left and right arguments. I just want to check whether a and b are almost equal.
msg292540 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-04-28 17:05
Done.
msg292548 -(view)Author: Raymond Hettinger (rhettinger)*(Python committer)Date: 2017-04-28 20:26
The patch looks good to me.
msg292668 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-05-01 16:18
New changeset5d7a8d0c13737fd531b722ad76c505ef47aac96a by Giampaolo Rodola in branch 'master':bpo-30190: improved error msg for assertAlmostEqual(delta=...) (#1331)https://github.com/python/cpython/commit/5d7a8d0c13737fd531b722ad76c505ef47aac96a
msg293350 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-05-09 21:30
New test produce deprecation warnings:/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:228: DeprecationWarning: invalid escape sequence \(  ["^1 != 2 within 7 places \(1 difference\)$", "^oops$",/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:229: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\)$",/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:230: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\) : oops$"])
msg293415 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-05-10 13:02
Mmm I can't see them. Am I supposed to enable this kind of warning somehow?
msg293416 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-05-10 13:07
$ ./python -WaLib/unittest/test/test_assertions.pyLib/unittest/test/test_assertions.py:228: DeprecationWarning: invalid escape sequence \(  ["^1 != 2 within 7 places \(1 difference\)$", "^oops$",Lib/unittest/test/test_assertions.py:229: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\)$",Lib/unittest/test/test_assertions.py:230: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\) : oops$"])...................................----------------------------------------------------------------------Ran 35 tests in 0.052sOK
msg293417 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-05-10 13:09
Warnings are not shown when the source is already compiled to .pyc file.$ find -name '*.py[co]' -exec rm '{}' +$ ./python -Wa -m test test_unittestRun tests sequentially0:00:00 load avg: 0.54 [1/1] test_unittest/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:228: DeprecationWarning: invalid escape sequence \(  ["^1 != 2 within 7 places \(1 difference\)$", "^oops$",/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:229: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\)$",/home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:230: DeprecationWarning: invalid escape sequence \(  "^1 != 2 within 7 places \(1 difference\) : oops$"])1 test OK.Total duration: 5 secTests result: SUCCESS
msg293418 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-05-10 13:10
OK thanks. Fix coming.
msg299138 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-07-25 21:05
Reopening as it needs backports for 2.7, 3.3, 3.4, 3.5 and 3.6.
msg299140 -(view)Author: Giampaolo Rodola' (giampaolo.rodola)*(Python committer)Date: 2017-07-25 21:06
Sorry, I accidentally picked up the wrong thread.
History
DateUserActionArgs
2022-04-11 14:58:45adminsetgithub: 74376
2017-07-25 21:06:29giampaolo.rodolasetstatus: pending -> closed
versions: - Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6
messages: +msg299140

resolution: fixed
stage: backport needed -> resolved
2017-07-25 21:05:30giampaolo.rodolasetstatus: closed -> pending
versions: + Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6
messages: +msg299138

resolution: fixed -> (no value)
stage: resolved -> backport needed
2017-05-10 18:13:40giampaolo.rodolasetstatus: open -> closed
2017-05-10 13:24:27giampaolo.rodolasetpull_requests: +pull_request1633
2017-05-10 13:10:48giampaolo.rodolasetmessages: +msg293418
2017-05-10 13:09:58serhiy.storchakasetmessages: +msg293417
2017-05-10 13:07:19serhiy.storchakasetmessages: +msg293416
2017-05-10 13:02:56giampaolo.rodolasetmessages: +msg293415
2017-05-09 21:30:45serhiy.storchakasetstatus: closed -> open

messages: +msg293350
2017-05-05 07:31:14berker.peksagsetstatus: open -> closed
type: enhancement
resolution: fixed
components: + Library (Lib)
stage: patch review -> resolved
2017-05-01 16:18:58giampaolo.rodolasetmessages: +msg292668
2017-04-28 20:26:01rhettingersetnosy: +rhettinger
messages: +msg292548
2017-04-28 17:05:26giampaolo.rodolasetmessages: +msg292540
2017-04-28 16:17:48giampaolo.rodolasetmessages: +msg292537
2017-04-28 05:02:48serhiy.storchakasetnosy: +serhiy.storchaka
messages: +msg292510
2017-04-27 20:56:33giampaolo.rodolasettitle: unittest's assertAlmostEqual should show the difference -> unittest's assertAlmostEqual improved error message
2017-04-27 20:53:36giampaolo.rodolasetmessages: +msg292482
stage: needs patch -> patch review
2017-04-27 20:52:25giampaolo.rodolasetpull_requests: +pull_request1439
2017-04-27 20:21:22giampaolo.rodolasetnosy: +rbcollins,ezio.melotti,michael.foord
2017-04-27 20:12:42giampaolo.rodolacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp