Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pytest testing Fibonacci

from fibonacci import fib

def test_fib():
    assert fib(10) == 55

Output:

============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/gabor/work/slides/python/examples/pytest/fib1
plugins: flake8-1.0.6, dash-1.17.0
collected 1 item

test_fibonacci.py .                                                      [100%]

============================== 1 passed in 0.00s ===============================
  • What if the user calls it with -3 ? We get the result to be 1. We don't want that.