mercredi 10 février 2016

Invoking Test Methods with a Method for a unittest.TestCase Subclass Python

I've been reading the documentation for the unittest module, but I haven't been able to decipher if it's even possible to do what I'm looking to do. Specifically, I'd like to be able to do something like the following class:

class TestMyCode(unittest.TestCase):

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

    # Not sure how to do implement this method below
    def run_tests(self):
        # This would run all of the tests in my class
        self.run()

The reason I would like to do this is because I would like to run my tests from within another Python file. E.g., say I'm writing code in another file:

from test_my_code import TestMyCode
tests = TestMyCode()
# Runs all of the tests from the TestMyCode subclass
tests.run_tests()

Is this possible?

Thanks

Aucun commentaire:

Enregistrer un commentaire