Approx — fuzzy compares (works on NumPy arrays):
assert 1 / 3 == approx(0.3333333333333)
Raises — test that errors do fire:
with pytest.raises(ZeroDivisionError):
1 / 0
Parametrize — one test, many cases:
@pytest.mark.parametrize("n", [1, 2, 3])
def test_square(n):
assert n**2 == n * n
Fixtures — just named arguments:
def test_printout(capsys):
print("hello")
assert "hello" in capsys.readouterr().out