I am trying to write unit tests for my Python package, and I am finding that, when I run the tests, AssertionErrors are not being raised, when they should be. Here is an MWE:
In exampleModule.py I have:
#! /usr/bin/env python
import unittest
class UnitTest(unittest.TestCase):
def runTest(self):
print("Starting test...")
a = 4
b = 5
self.assertEqual(a,b)
print("TEST COMPLETE")
return
And in testError.py I have:
#! /usr/bin/env python
import unittest
class AllTests(unittest.TestCase):
def testExample(self):
from exampleModule import UnitTest
UT = UnitTest()
UT.run()
return
if __name__ == '__main__':
unittest.main()
When I run testError.py I expect to see the AssertionError reported from the UnitTest in exampleModule.py, however, I simply see the following:
> ./testError.py
Starting test...
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
Why is the AssertionError not being raised? If I place the UnitTest() class in testError.py (i.e., have everything in the same file) then the AssertionError is raised. So why, when UnitTest is stored in a different file, does the error not get raised?
nosetestsornose2orpytest, they will discover and make tests without using the__main__?