Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ?
Peter J. Holzer
hjp-python at hjp.at
Fri Feb 24 14:12:44 EST 2023
On 2023-02-24 16:12:10 +1300, dn via Python-list wrote:
> In some ways, providing this information seems appropriate. Curiously, this
> does not even occur during an assert exception - despite the
> value/relationship being the whole point of using the command!
>
> x = 1
> assert x == 2
>
> AssertionError (and that's it)
Pytest is great there. If an assertion in a test case fails it analyzes
the expression to give you various levels of details:
======================================== test session starts ========================================
platform linux -- Python 3.10.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.0
rootdir: /home/hjp/tmp/t
plugins: cov-3.0.0, anyio-3.6.1
collected 1 item
test_a.py F [100%]
============================================= FAILURES ==============================================
______________________________________________ test_a _______________________________________________
def test_a():
a = [1, 2, 3]
b = {"a": a, "b": 2}
> assert len(a) == len(b)
E AssertionError: assert 3 == 2
E + where 3 = len([1, 2, 3])
E + and 2 = len({'a': [1, 2, 3], 'b': 2})
test_a.py:7: AssertionError
====================================== short test summary info ======================================
FAILED test_a.py::test_a - AssertionError: assert 3 == 2
========================================= 1 failed in 0.09s =========================================
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230224/8250bb13/attachment.sig>
More information about the Python-list
mailing list