exceptions are raised assert x == 1 assert x != 1 assert x in [1, 2, 3] assert x < 5 pytest.raises(ZeroDivisionError, lambda x: 1 / x, 0) with pytest.raises(ZeroDivisionError): 1 / 0
4 E assert 3 == 4 E + where 3 = sum([0, 1, 2]) E + where [0, 1, 2] = range(3) def test_list(): > assert [1, 2, 3] == [1, 2] E assert [1, 2, 3] == [1, 2] E Left contains more items, first extra item: 3 def test_long(): a = '-'*50 + 'a' + '-'*50 b = '-'*50 + 'b' + '-'*50 > assert a == b E assert '--------...---------' == '---------...---------' E Skipping 44 identical leading characters in diff E Skipping 45 identical trailing characters in diff E - ----------a--------- E ? ^ E + ----------b--------- E ? ^
all classes prefixed with Test • specific functions or classes with -k from foopackage import foomodule def test_add(): assert foomodule.add(1, 2) == 3 class TestFoo(object): def test_negative(self): assert foomodule.add(1, -1) == 0 $ py.test -k "TestFoo and test_negative"