Skip to content
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

Verbosity setting does not affect truncation of sequences when comparing their length #11777

Closed
dpitch40 opened this issue Jan 5, 2024 · 1 comment · Fixed by #12192
Closed
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity

Comments

@dpitch40
Copy link

dpitch40 commented Jan 5, 2024

If a comparison on the length of a sequence fails, the sequence is truncated in the failure explanation regardless of the verbosity setting.

Example script:

def test_list():
    l = list(range(50))
    assert l == []

def test_list_len():
    l = list(range(50))
    assert len(l) == 49

def test_dict():
    d = dict(zip(range(50), range(50)))
    assert d == {}

def test_dict_len():
    d = dict(zip(range(50), range(50)))
    assert len(d) == 49

Output of python3 -m pytest test_truncation.py:

====================================================== FAILURES ======================================================
_____________________________________________________ test_list ______________________________________________________

    def test_list():
        l = list(range(50))
>       assert l == []
E       assert [0, 1, 2, 3, 4, 5, ...] == []
E         Left contains 50 more items, first extra item: 0
E         Use -v to get more diff

test_truncation.py:3: AssertionError
___________________________________________________ test_list_len ____________________________________________________

    def test_list_len():
        l = list(range(50))
>       assert len(l) == 49
E       assert 50 == 49
E        +  where 50 = len([0, 1, 2, 3, 4, 5, ...])

test_truncation.py:7: AssertionError
_____________________________________________________ test_dict ______________________________________________________

    def test_dict():
        d = dict(zip(range(50), range(50)))
>       assert d == {}
E       AssertionError: assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {}
E         Left contains 50 more items:
E         {0: 0,
E          1: 1,
E          2: 2,
E          3: 3,
E          4: 4,
E          5: 5,...
E         
E         ...Full output truncated (45 lines hidden), use '-vv' to show

test_truncation.py:11: AssertionError
___________________________________________________ test_dict_len ____________________________________________________

    def test_dict_len():
        d = dict(zip(range(50), range(50)))
>       assert len(d) == 49
E       assert 50 == 49
E        +  where 50 = len({0: 0, 1: 1, 2: 2, 3: 3, ...})

test_truncation.py:15: AssertionError
============================================== short test summary info ===============================================
FAILED test_truncation.py::test_list - assert [0, 1, 2, 3, 4, 5, ...] == []
FAILED test_truncation.py::test_list_len - assert 50 == 49
FAILED test_truncation.py::test_dict - AssertionError: assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {}
FAILED test_truncation.py::test_dict_len - assert 50 == 49

Output of python3 -m pytest test_truncation.py -v:

====================================================== FAILURES ======================================================
_____________________________________________________ test_list ______________________________________________________

    def test_list():
        l = list(range(50))
>       assert l == []
E       AssertionError: assert [0, 1, 2, 3, 4, 5, ...] == []
E         Left contains 50 more items, first extra item: 0
E         Full diff:
E           [
E         -  ,
E         +  0,
E         ?  +
E         +  1,...
E         
E         ...Full output truncated (49 lines hidden), use '-vv' to show

test_truncation.py:3: AssertionError
___________________________________________________ test_list_len ____________________________________________________

    def test_list_len():
        l = list(range(50))
>       assert len(l) == 49
E       assert 50 == 49
E        +  where 50 = len([0, 1, 2, 3, 4, 5, ...])

test_truncation.py:7: AssertionError
_____________________________________________________ test_dict ______________________________________________________

    def test_dict():
        d = dict(zip(range(50), range(50)))
>       assert d == {}
E       AssertionError: assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {}
E         Left contains 50 more items:
E         {0: 0,
E          1: 1,
E          2: 2,
E          3: 3,
E          4: 4,
E          5: 5,...
E         
E         ...Full output truncated (98 lines hidden), use '-vv' to show

test_truncation.py:11: AssertionError
___________________________________________________ test_dict_len ____________________________________________________

    def test_dict_len():
        d = dict(zip(range(50), range(50)))
>       assert len(d) == 49
E       assert 50 == 49
E        +  where 50 = len({0: 0, 1: 1, 2: 2, 3: 3, ...})

test_truncation.py:15: AssertionError
============================================== short test summary info ===============================================
FAILED test_truncation.py::test_list - AssertionError: assert [0, 1, 2, 3, 4, 5, ...] == []
FAILED test_truncation.py::test_list_len - assert 50 == 49
FAILED test_truncation.py::test_dict - AssertionError: assert {0: 0, 1: 1, 2: 2, 3: 3, ...} == {}
FAILED test_truncation.py::test_dict_len - assert 50 == 49

Output of python3 -m pytest test_truncation.py -vv:

====================================================== FAILURES ======================================================
_____________________________________________________ test_list ______________________________________________________

    def test_list():
        l = list(range(50))
>       assert l == []
E       assert [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] == []
E         Left contains 50 more items, first extra item: 0
E         Full diff:
E           [
E         -  ,
E         +  0,
E         ?  +
E         +  1,
E         +  2,
E         +  3,
E         +  4,
E         +  5,
E         +  6,
E         +  7,
E         +  8,
E         +  9,
E         +  10,
E         +  11,
E         +  12,
E         +  13,
E         +  14,
E         +  15,
E         +  16,
E         +  17,
E         +  18,
E         +  19,
E         +  20,
E         +  21,
E         +  22,
E         +  23,
E         +  24,
E         +  25,
E         +  26,
E         +  27,
E         +  28,
E         +  29,
E         +  30,
E         +  31,
E         +  32,
E         +  33,
E         +  34,
E         +  35,
E         +  36,
E         +  37,
E         +  38,
E         +  39,
E         +  40,
E         +  41,
E         +  42,
E         +  43,
E         +  44,
E         +  45,
E         +  46,
E         +  47,
E         +  48,
E         +  49,
E           ]

test_truncation.py:3: AssertionError
___________________________________________________ test_list_len ____________________________________________________

    def test_list_len():
        l = list(range(50))
>       assert len(l) == 49
E       assert 50 == 49
E        +  where 50 = len([0, 1, 2, 3, 4, 5, ...])

test_truncation.py:7: AssertionError
_____________________________________________________ test_dict ______________________________________________________

    def test_dict():
        d = dict(zip(range(50), range(50)))
>       assert d == {}
E       assert {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17, 18: 18, 19: 19, 20: 20, 21: 21, 22: 22, 23: 23, 24: 24, 25: 25, 26: 26, 27: 27, 28: 28, 29: 29, 30: 30, 31: 31, 32: 32, 33: 33, 34: 34, 35: 35, 36: 36, 37: 37, 38: 38, 39: 39, 40: 40, 41: 41, 42: 42, 43: 43, 44: 44, 45: 45, 46: 46, 47: 47, 48: 48, 49: 49} == {}
E         Left contains 50 more items:
E         {0: 0,
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         Full diff:
E           {
E         -  ,
E         +  0: 0,
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           }

test_truncation.py:11: AssertionError
___________________________________________________ test_dict_len ____________________________________________________

    def test_dict_len():
        d = dict(zip(range(50), range(50)))
>       assert len(d) == 49
E       assert 50 == 49
E        +  where 50 = len({0: 0, 1: 1, 2: 2, 3: 3, ...})

test_truncation.py:15: AssertionError
============================================== short test summary info ===============================================
FAILED test_truncation.py::test_list - assert [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,...
FAILED test_truncation.py::test_list_len - assert 50 == 49
FAILED test_truncation.py::test_dict - assert {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 1...
FAILED test_truncation.py::test_dict_len - assert 50 == 49

Why are the sequences always truncated in the explanations of the length comparison failures, regardless of verbosity?

Python 3.10.12, pytest-7.4.4, my OS is Linux Mint 21.2.

pip list output attached:

pip_list.txt

@Zac-HD Zac-HD added type: question general question, might be closed after 2 weeks of inactivity topic: reporting related to terminal output and user-facing messages and errors labels Feb 17, 2024
@HolyMagician03-UMich
Copy link
Contributor

Hi! I can try working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants