Reset previous run for Unit tests for functions in a Jupyter notebook?

13 Views Asked by At

I have the following simple function in a Jupyter Notebook:

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

and then I do some UnitTest as follows in same notebook below:

import unittest

class TestNotebook(unittest.TestCase):
    
    def test_add(self):
        self.assertEqual(add(2, 2), 4)
        

unittest.main(argv=[''], verbosity=2, exit=False)

I get the following output:

test_add (__main__.TestNotebook.test_add) ... ok
test_drop_duplicates (__main__.TestSilver.test_drop_duplicates) ... ERROR
test_make_url_v1 (__main__.TestUrl.test_make_url_v1) ... ERROR
test_make_url_v2 (__main__.TestUrl.test_make_url_v2) ... ok
ERROR: test_make_url_v1 (__main__.TestUrl.test_make_url_v1)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/ipykernel_1252/4074376083.py", line 9, in test_make_url_v1
    date = datetime.date(2019, 12, 311)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: day is out of range for month

----------------------------------------------------------------------
Ran 4 tests in 0.130s

FAILED (errors=2)

The question is: As you can see, I only executed one test which was test_add but in the output, I can still see some old (work-in-progress) tests that I ran like an hour ago? How do I clear the log or memory so only current test that is ran is printed in logs?

0

There are 0 best solutions below