Tutorial by Examples

py.test is one of several third party testing libraries that are available for Python. It can be installed using pip with pip install pytest The Code to Test Say we are testing an addition function in projectroot/module/code.py: # projectroot/module/code.py def add(a, b): return a + b ...
A failing test will provide helpful output as to what went wrong: # projectroot/tests/test_code.py from module import code def test_add__failing(): assert code.add(10, 11) == 33 Results: $ py.test ================================================== test session starts ===============...
More complicated tests sometimes need to have things set up before you run the code you want to test. It is possible to do this in the test function itself, but then you end up with large test functions doing so much that it is difficult to tell where the setup stops and the test begins. You can als...

Page 1 of 1