Im running some unittests in Python and would like to call a function after all of the test cases have been run.
class MyTestCase(TestCase):
def setUp(self):
self.credentials = credentials
def tearDown(self):
print("finished running " + self._testMethodName)
def tearDownModule(self):
print("finished running all tests")
def test_1(self):
#do something
def test_2(self):
#do something else
setUp and tearDown are running before and after each individual test. Yet i would like to call a function after all tests are finished running (in this case test_1 and test_2).
From the documentation looks like the tearDownModule() function should do it, yet this doesnt seem to be called.
tearDownModule
is for use on the module scope, not as a method. Instead, you probably want tearDownClass
:
class MyTestCase(TestCase):
@classmethod
def tearDownClass(cls):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With