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

mycalc as a self testing module

  • file
import mycalc
print(mycalc.add(19, 23))
$ python use_mycalc.py
42
def test_add():
    print('Testing  {}'.format(__file__))
    assert add(1, 1) == 2
    assert add(-1, 1) == 0
    # assert add(-99, 1) == 0 # AssertionError

def add(a, b):
    return a + b

if __name__ == '__main__':
    test_add()
$ python mycalc.py
Self testing  mycalc.py