- pytest Quick Start Guide
- Bruno Oliveira
- 188字
- 2021-07-16 17:51:28
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
推薦閱讀
- FreeSWITCH 1.2
- GPS/GNSS原理與應用(第3版)
- Proxmox High Availability
- 物聯網+BIM:構建數字孿生的未來
- 物聯網信息安全
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 無人機通信
- React:Cross-Platform Application Development with React Native
- Building RESTful Web services with Go
- 新手易學:新手學淘寶開店
- Learning Storm
- React Cookbook
- 網絡利他行為研究:積極心理學的視角
- 無線傳感器網絡定位技術
- 現代通信系統(第5版)