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

Test the Fibonacci

import unittest
from fibonacci import fib

class TestFibo(unittest.TestCase):

    def test_fib(self):
        self.assertEqual(fib(7), 8)
        self.assertEqual(fib(10), 34)
        self.assertEqual(fib(42), 165580141)

We don’t need the extra code to trigger the unittest from inside our module. We can just run it using the follow command line:

$ python -m unittest test_fibonacci_with_unittest.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK