Running specific unit tests in python from main ()

I am trying to run only one test from the unit tests provided in a class. So, assuming

class MytestSuite(unittest.TestCase):
    def test_false(self):
        a = False
        self.assertFalse(a, "Its false")

    def test_true(self):
        a = True
        self.assertTrue(a, "Its true")

I would like to run only test_false. Based on the Q&A provided on this site and on the Internet, I used the following lines of code in my main class

if __name__ == "__main__":  #Indentation was wronng
    singletest = unittest.TestSuite()
    singletest.addTest(MytestSuite().test_false)
    unittest.TextTestRunner().run(singletest)

I keep getting errors when trying to add a test. Mainly:

  File "C:\Python27\Lib\unittest\case.py", line 189, in __init__
(self.__class__, methodName))
ValueError: no such test method in <class '__main__.MytestSuite'>: runTest

runTest ? , . : A, 1 B, 2. , . , . , .

+4
1

addTest. , , TestCase ( MyTestSuite), , .

singletest.addTest(MyTestSuite('test_false'))

.

+4

All Articles