lundi 6 juillet 2015

Avoid Python Unit Test Class to invoke tests on import

I have a class called Test as follows

class Tests(unittest.TestCase):
    def testAddition(self):
        self.assertTrue(True)

The unit test runs all fine. The issue is when I import this class for other implementations somewhere else like this, from package import Tests on import the test cases get invoked automatically. Is there a way to avoid this.

I would like to import as this:

from package import Tests
def some_method:
test = Tests()
for client in clients:
    test.testAddition(self, client)

Aucun commentaire:

Enregistrer un commentaire