简体   繁体   中英

setupclass in unittest is not being called in python 2.6

I use Python 2.6.2 and tried to execute the basic unit test case py file below,

class First(unittest.TestCase):

@classmethod
def setUpClass(cls):
    print ("setting up")

def test1(self):
    pass


if __name__ == '__main__':
    unittest.main()

This calls only the test1 but before calling test1 it should call setUpClass and initialize my objectes.

This works as expected in Python 2.7.6 and prints me setting up first and then proceed to test1. But in python 2.6 it directly goes to test1. How can i solve this issue?

From the documentation to unittest :

setUpClass()

...

New in version 2.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM