Why pytest?
Pytest is a mature and full-featured testing framework, from small tests to large scale functional tests for applications and libraries alike.
Pytest is simple to get started with. To write tests, you don't need classes; you can write simple functions that start with test
and use Python's built-in assert
statement:
from fibo import fibonacci def test_fibo(): assert fibonacci(4) == 3
That's it. You import your code, write a function, and use plain assert calls to ensure they are working as you expect: no need to make a subclass and use various self.assert*
methods to do your testing. And the beautiful thing is that it also provides helpful output when an assertion fails:
λ pytest test_fibo2.py -q F [100%] ============================= FAILURES ============================== _____________________________ test_fibo _____________________________ def test_fibo(): > assert...