官术网_书友最值得收藏!

Lists

Assertion failures for lists also show only differing items by default:

____________________ test_get_starting_equiment _____________________

def test_get_starting_equiment():
expected = ['long sword', 'shield']
> assert get_starting_equipment('warrior') == expected
E AssertionError: assert ['long sword'...et', 'shield'] == ['long sword', 'shield']
E At index 1 diff: 'warrior set' != 'shield'
E Left contains more items, first extra item: 'shield'
E Use -v to get the full diff

tests\test_assert_demo.py:71: AssertionError

Note that pytest shows which index differs, and also that the -v flag can be used to show the complete difference between the lists:

____________________ test_get_starting_equiment _____________________

def test_get_starting_equiment():
expected = ['long sword', 'shield']
> assert get_starting_equipment('warrior') == expected
E AssertionError: assert ['long sword'...et', 'shield'] == ['long sword', 'shield']
E At index 1 diff: 'warrior set' != 'shield'
E Left contains more items, first extra item: 'shield'
E Full diff:
E - ['long sword', 'warrior set', 'shield']
E ? ---------------
E + ['long sword', 'shield']

tests\test_assert_demo.py:71: AssertionError

If the difference is too big, pytest is smart enough to show only a portion to avoid showing too much output, displaying a message like the following:

E         ...Full output truncated (100 lines hidden), use '-vv' to show
主站蜘蛛池模板: 宜川县| 海淀区| 大埔区| 独山县| 额尔古纳市| 留坝县| 景泰县| 伊宁县| 天水市| 富蕴县| 略阳县| 乐昌市| 宝丰县| 肃宁县| 嵩明县| 正安县| 高密市| 方山县| 哈巴河县| 张家口市| 崇左市| 娄烦县| 平阳县| 郸城县| 绿春县| 阿克苏市| 灌云县| 土默特右旗| 南投市| 乌恰县| 舟曲县| 秭归县| 枝江市| 蛟河市| 玉环县| 屯留县| 资中县| 高邮市| 千阳县| 威海市| 新源县|