-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Description
Given a file:
a = [1, 2, 3]
b = [1, 2]
def test_a():
assert len(a) == len(b)
def test_bigger_assertion():
first_dict = {a: a for a in range(100)}
second_dict = {b: b for b in range(1, 101)}
assert first_dict == second_dictpytest will output
✔ pytest test_file.py
============================================================================================== test session starts ==============================================================================================
platform darwin -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: /Users/jkahn/wave/src/external/pytest-clarity
collected 2 items
test_file.py FF [100%]
=================================================================================================== FAILURES ====================================================================================================
____________________________________________________________________________________________________ test_a _____________________________________________________________________________________________________
def test_a():
> assert len(a) == len(b)
E assert 3 == 2
E + where 3 = len([1, 2, 3])
E + and 2 = len([1, 2])
test_file.py:5: AssertionError
_____________________________________________________________________________________________ test_bigger_assertion _____________________________________________________________________________________________
def test_bigger_assertion():
first_dict = {a: a for a in range(100)}
second_dict = {b: b for b in range(1, 101)}
> assert first_dict == second_dict
E assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {1: 1, 2: 2, 3: 3, 4: 4, ...}
E Omitting 99 identical items, use -vv to show
E Left contains 1 more item:
E {0: 0}
E Right contains 1 more item:
E {100: 100}
E Use -v to get the full diff
test_file.py:10: AssertionError
=============================================================================================== 2 failed in 0.04s ===============================================================================================
However if I increase the verbosity, so that I can see more of the diff (either -v or -vv) like so, then it removed the helpful assertion rewriting from the first test
↵ 1 pytest test_file.py -vv
============================================================================================== test session starts ==============================================================================================
platform darwin -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- /Users/jkahn/.local/share/virtualenvs/pytest-clarity-JGV2Xd-w/bin/python3.7
cachedir: .pytest_cache
rootdir: /Users/jkahn/wave/src/external/pytest-clarity
collected 2 items
test_file.py::test_a FAILED [ 50%]
test_file.py::test_bigger_assertion FAILED [100%]
=================================================================================================== FAILURES ====================================================================================================
____________________________________________________________________________________________________ test_a _____________________________________________________________________________________________________
def test_a():
> assert len(a) == len(b)
E assert 3 == 2
E -3
E +2
test_file.py:5: AssertionError
_____________________________________________________________________________________________ test_bigger_assertion _____________________________________________________________________________________________
def test_bigger_assertion():
first_dict = {a: a for a in range(100)}
second_dict = {b: b for b in range(1, 101)}
> assert first_dict == second_dict
E assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {1: 1, 2: 2, 3: 3, 4: 4, ...}
E Common items:
E {1: 1,
E 2: 2,
E 3: 3,
E 4: 4,
E 5: 5,
E 6: 6,
E 7: 7,
E 8: 8,
E 9: 9,
E 10: 10,
E 11: 11,
E 12: 12,
E 13: 13,
E 14: 14,
E 15: 15,
E 16: 16,
E 17: 17,
E 18: 18,
E 19: 19,
E 20: 20,
E 21: 21,
E 22: 22,
E 23: 23,
E 24: 24,
E 25: 25,
E 26: 26,
E 27: 27,
E 28: 28,
E 29: 29,
E 30: 30,
E 31: 31,
E 32: 32,
E 33: 33,
E 34: 34,
E 35: 35,
E 36: 36,
E 37: 37,
E 38: 38,
E 39: 39,
E 40: 40,
E 41: 41,
E 42: 42,
E 43: 43,
E 44: 44,
E 45: 45,
E 46: 46,
E 47: 47,
E 48: 48,
E 49: 49,
E 50: 50,
E 51: 51,
E 52: 52,
E 53: 53,
E 54: 54,
E 55: 55,
E 56: 56,
E 57: 57,
E 58: 58,
E 59: 59,
E 60: 60,
E 61: 61,
E 62: 62,
E 63: 63,
E 64: 64,
E 65: 65,
E 66: 66,
E 67: 67,
E 68: 68,
E 69: 69,
E 70: 70,
E 71: 71,
E 72: 72,
E 73: 73,
E 74: 74,
E 75: 75,
E 76: 76,
E 77: 77,
E 78: 78,
E 79: 79,
E 80: 80,
E 81: 81,
E 82: 82,
E 83: 83,
E 84: 84,
E 85: 85,
E 86: 86,
E 87: 87,
E 88: 88,
E 89: 89,
E 90: 90,
E 91: 91,
E 92: 92,
E 93: 93,
E 94: 94,
E 95: 95,
E 96: 96,
E 97: 97,
E 98: 98,
E 99: 99}
E Left contains 1 more item:
E {0: 0}
E Right contains 1 more item:
E {100: 100}
E Full diff:
E - {0: 0,
E - 1: 1,
E ? ^
E + {1: 1,
E ? ^
E 2: 2,
E 3: 3,
E 4: 4,
E 5: 5,
E 6: 6,
E 7: 7,
E 8: 8,
E 9: 9,
E 10: 10,
E 11: 11,
E 12: 12,
E 13: 13,
E 14: 14,
E 15: 15,
E 16: 16,
E 17: 17,
E 18: 18,
E 19: 19,
E 20: 20,
E 21: 21,
E 22: 22,
E 23: 23,
E 24: 24,
E 25: 25,
E 26: 26,
E 27: 27,
E 28: 28,
E 29: 29,
E 30: 30,
E 31: 31,
E 32: 32,
E 33: 33,
E 34: 34,
E 35: 35,
E 36: 36,
E 37: 37,
E 38: 38,
E 39: 39,
E 40: 40,
E 41: 41,
E 42: 42,
E 43: 43,
E 44: 44,
E 45: 45,
E 46: 46,
E 47: 47,
E 48: 48,
E 49: 49,
E 50: 50,
E 51: 51,
E 52: 52,
E 53: 53,
E 54: 54,
E 55: 55,
E 56: 56,
E 57: 57,
E 58: 58,
E 59: 59,
E 60: 60,
E 61: 61,
E 62: 62,
E 63: 63,
E 64: 64,
E 65: 65,
E 66: 66,
E 67: 67,
E 68: 68,
E 69: 69,
E 70: 70,
E 71: 71,
E 72: 72,
E 73: 73,
E 74: 74,
E 75: 75,
E 76: 76,
E 77: 77,
E 78: 78,
E 79: 79,
E 80: 80,
E 81: 81,
E 82: 82,
E 83: 83,
E 84: 84,
E 85: 85,
E 86: 86,
E 87: 87,
E 88: 88,
E 89: 89,
E 90: 90,
E 91: 91,
E 92: 92,
E 93: 93,
E 94: 94,
E 95: 95,
E 96: 96,
E 97: 97,
E 98: 98,
E - 99: 99}
E ? ^
E + 99: 99,
E ? ^
E + 100: 100}
test_file.py:10: AssertionError
This is caused by these two lines here:
pytest/src/_pytest/assertion/util.py
Lines 148 to 149 in c58b0fb
| elif verbose > 0: | |
| explanation = _compare_eq_verbose(left, right) |
Which was introduced here
#4607
I came across this when working on plugin stuff (I opened this to get help: #5931). Which is related in a way, in that the Rewriter isn't being used when assertrepr_compare (either builtin or as a plugin) returns something.
Metadata
Metadata
Assignees
Labels
No labels