user393267
user393267

Reputation:

Is there a way to know if a unittest class is done with all the tests?

I have a class that implement unittest.TestCase; I would like to know when all the tests has been executed; and perform some operation.

Although I can't see how can I get this info; the class does not seem to have a clue about the number of tests, or at least I was not able to find out where this info is hidden.

I would like to do a simple check, so I can trigger another class in the same file, to perform some analysis and formatting data. Am I looking for something that in fact is not possible?

Upvotes: 0

Views: 31

Answers (1)

alecxe
alecxe

Reputation: 473763

There is a special class method for that - tearDownClass():

A class method called after tests in an individual class have run.

import unittest

class MyTestCase(unittest.TestCase):
    @classmethod
    def tearDownClass(cls):
        print("All the tests in this class are done")

    def test_something(self):
        self.assertTrue(True)

    def test_something_else(self):
        self.assertFalse(False)

Upvotes: 1

Related Questions