-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unittest's assertAlmostEqual improved error message #74376
Comments
When comparing 2 numbers as "self.assertAlmostEqual(a, b, delta=1000)" the error message looks like this:
Especially 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:
|
PR: #1331 |
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? |
Thanks for chiming in.
Yes, probably. I will change that.
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. |
Done. |
The patch looks good to me. |
New test produce deprecation warnings: /home/serhiy/py/cpython/Lib/unittest/test/test_assertions.py:228: DeprecationWarning: invalid escape sequence \( |
Mmm I can't see them. Am I supposed to enable this kind of warning somehow? |
$ ./python -Wa Lib/unittest/test/test_assertions.py
Lib/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.052s OK |
Warnings are not shown when the source is already compiled to .pyc file. $ find -name '*.py[co]' -exec rm '{}' +
$ ./python -Wa -m test test_unittest
Run tests sequentially
0: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 sec |
OK thanks. Fix coming. |
Reopening as it needs backports for 2.7, 3.3, 3.4, 3.5 and 3.6. |
Sorry, I accidentally picked up the wrong thread. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: