简体   繁体   中英

setUp section in unit-tests seems to be ignored

class MyTests(unittest.TestCase):

    def SetUp(self):
        """ Setting up expected default values """
        self.test = RandomTest()

    def testReturnsArrayWithTuples(self):
        result = self.test.next()  # Error
        self.assert_(len(result), 5)

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

I have a basic test, but it fails with this error message:

AttributeError: 'MyTests' object has no attribute 'test'

Eclipse intellisense is showing me self.test though. What am I missing please?

Ok, its quite embarrassing, as it was just a typo. :)

def SetUp(self): has to be lowercase def setUp(self): in order to be found and executed.

I hope it prevents someone else chasing ghosts like I did.

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