IPython-Unittest

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

pip install ipython_unittest

https://github.com/JoaoFelipe/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



class JupyterTest(unittest.TestCase):

    def test_soma_1_1_retorna_2(self):
        'soma 1 + 1 retorna 2'
        self.assertEqual(soma(1, 1), 2)

    def test_soma_1_2_retorna_3(self):
        'soma 1 + 2 retorna 3'
        self.assertEqual(soma(1, 2), 3)

    def test_soma_2_2_retorna_4(self):
        'soma 2 + 2 retorna 4'
        self.assertEqual(soma(2, 2), 4)

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

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

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)


F..
======================================================================
FAIL: test_soma_1_1_retorna_2 (__main__.JupyterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython-input-5-f70e60213ac3>", line 7, in test_soma_1_1_retorna_2
    self.assertEqual(soma(1, 1), 2)
AssertionError: 3 != 2

----------------------------------------------------------------------
Ran 3 tests in 0.005s

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

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [13]:


In [6]:



...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

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

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 [ ]:

  • 4:15:29 PM -> 4:15:38 PM = null, null