Unit Test not running

PythonUnit Testing

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontutucaView Question on Stackoverflow
Solution 1 - PythonMartijn PietersView Answer on Stackoverflow