pytest Quick Start Guide
上QQ阅读APP看书,第一时间看更新

Dictionaries and sets

Dictionaries are probably one of the most used data structures in Python, so, unsurprisingly, pytest has specialized representation for them:

_______________________ test_starting_health ________________________

def test_starting_health():
expected = {'warrior': 85, 'sorcerer': 50}
> assert get_classes_starting_health() == expected
E AssertionError: assert {'knight': 95...'warrior': 85} == {'sorcerer': 50, 'warrior': 85}
E Omitting 1 identical items, use -vv to show
E Differing items:
E {'sorcerer': 55} != {'sorcerer': 50}
E Left contains more items:
E {'knight': 95}
E Use -v to get the full diff

Sets also have similar output:

________________________ test_player_classes ________________________

def test_player_classes():
> assert get_player_classes() == {'warrior', 'sorcerer'}
E AssertionError: assert {'knight', 's...r', 'warrior'} == {'sorcerer', 'warrior'}
E Extra items in the left set:
E 'knight'
E Use -v to get the full diff

As with lists, there are also -v and -vv options for displaying more detailed output.