Pytest

Using pytest

cd PACKAGENAME

pytest PACKAGENAME

Run a test file

pytest PACKAGENAME/tests/script.py

Run a test

pytest PACKAGENAME/tests/script.py -k test_a

pytest script.py::Class::test_a

 Drop into python debugger

pytest PACKAGENAME/tests/script.py --pdb

 See print statments

pytest -rP

 Skip a test

@pytest.mark.skip(reason="no way of currently testing this")

det test_x():

    pass

 

pytest -m "not slow"

 Parmeterize a test


Test an error

with pytest.raises(RuntimeError):

    broken_function()


def test_split_fails():

    with pytest.raises(TypeError):

        s = 'hello world'

        s.split(2)