pip install ipython_unittest
In [16]:
def soma(x, y):
return x + y
In [ ]:
%%write
In [ ]:
%%external
python
In [19]:
%%unittest -p 2 -u
"soma 1 + 1 retorna 2"
assert soma(1, 1) == 2
"soma 1 + 2 retorna 3"
assert soma(1, 2) == 3
"soma 2 + 2 retorna 4"
assert soma(2, 2) == 4
Out[19]:
In [ ]:
In [8]:
%load_ext ipython_unittest.dojo
In [5]:
import unittest
import sys
class JupyterTest(unittest.TestCase):
def test_soma_1_1_retorna_2(self):
self.assertEqual(soma(1, 1), 2)
def test_soma_1_2_retorna_3(self):
self.assertEqual(soma(1, 2), 3)
def test_soma_2_2_retorna_4(self):
self.assertEqual(soma(2, 2), 4)
suite = unittest.TestLoader().loadTestsFromTestCase(JupyterTest)
unittest.TextTestRunner(verbosity=1, stream=sys.stdout).run(suite)
Out[5]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [13]:
In [6]:
Out[6]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
pip install ipython_unittest
In [ ]: