IPython-Unittest

João Felipe Nicolaci Pimentel (joaofelipenp@gmail.com)

pip install ipython_unittest

https://github.com/JoaoFelipe/ipython-unittest


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

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



class JupyterTest(unittest.TestCase):

    def test_1_plus_1_equals_2(self):
        '1 plus 1 equals 2'
        self.assertEqual(sum(1, 1), 2)

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

    def test_3(self):
        ''
        self.assertEqual(sum(2, 2), 4)

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

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

In [16]:
%load_ext ipython_unittest

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [13]:
import unittest
import sys

In [14]:
class JupyterTest(unittest.TestCase):

    def test_1(self):
        self.assertEqual(sum(1, 1), 2)

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

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

In [15]:
suite = unittest.TestLoader().loadTestsFromTestCase(JupyterTest)
unittest.TextTestRunner(verbosity=1, stream=sys.stderr).run(suite)


.FF
======================================================================
FAIL: test_2 (__main__.JupyterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython-input-14-d2d9024f56a6>", line 7, in test_2
    self.assertEqual(sum(1, 2), 3)
AssertionError: 2 != 3

======================================================================
FAIL: test_3 (__main__.JupyterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython-input-14-d2d9024f56a6>", line 10, in test_3
    self.assertEqual(sum(2, 2), 4)
AssertionError: 3 != 4

----------------------------------------------------------------------
Ran 3 tests in 0.006s

FAILED (failures=2)
Out[15]:
<unittest.runner.TextTestResult run=3 errors=0 failures=2>

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:

IPython-Unittest

João Felipe Nicolaci Pimentel (joaofelipenp@gmail.com)

pip install ipython_unittest

https://github.com/JoaoFelipe/ipython-unittest


In [ ]: