In [15]:
%reload_ext ipython_unittest



In [16]:
def sum(x, y):
    return x + y

Simple asserts


In [17]:
%%unittest --dojo
assert sum(1, 1) == 2
assert sum(1, 2) == 3
assert sum(2, 2) == 4


...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Out[17]:
<unittest.runner.TextTestResult run=3 errors=0 failures=0>

Asserts with method names


In [ ]:
%%unittest -c
"1 plus 1 equals 2"
assert sum(1, 1) == 2
"1 plus 2 equals 3"
assert sum(1, 2) == 3
"2 plus 2 equals 4"
assert sum(2, 2) == 4

Test methods


In [ ]:
%%unittest_testcase -t MyTestCase
def test_1_plus_1_equals_2(self):
    self.assertEqual(sum(1, 1), 2)
    
def test_1_plus_2_equals_3(self):
    self.assertEqual(sum(1, 2), 3)
    
def test_2_plus_2_equals_4(self):
    self.assertEqual(sum(2, 2), 4)

Run all test cases


In [ ]:
%%unittest_main
class MyTestCase(unittest.TestCase):
    def test_1_plus_1_equals_2(self):
        self.assertEqual(sum(1, 1), 2)

    def test_1_plus_2_equals_3(self):
        self.assertEqual(sum(1, 2), 3)

    def test_2_plus_2_equals_4(self):
        self.assertEqual(sum(2, 2), 4)