Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

python - Unit Test not running

I'm getting stuck with some unittests.

Here's the simplest example I could come up with:

#testito.py
import unittest

class Prueba(unittest.TestCase):

    def setUp(self):
        pass
    def printsTrue(self):
        self.assertTrue(True)

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

Problem is, running this has no effect:

$ python testito.py 

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

I'm scratching my head as I don't see any problem with the code above. It happened with a couple of tests now and I don't really know what to do next. Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By default, only functions whose name that start with test are run:

class Prueba(unittest.TestCase):

    def setUp(self):
        pass
    def testPrintsTrue(self):
        self.assertTrue(True)

From the unittest basic example:

A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...