Python 3.6.7 in Jupyter Notebook. Running in Lubuntu 18.04.2 LTS, which is itself running in Virtual Box.
I am learning to use the module unittest. It was my understanding that each individual method was a test, more or less confirmed by this other question: Python unittest counting the number of tests
Nevertheless, when I run this code:
import unittest
def square(x):
return x * x
class TestSquareFunction(unittest.TestCase):
def test_positive(self):
a = 2.0
self.assertEqual(square(a), 4.0)
def test_negative(self):
a = -3.0
self.assertEqual(square(a), 9.0)
if __name__ == '__main__':
unittest.main(argv=['first-arg-is-ignored'], exit=False)
I get the result:
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s
OK
When I was expecting 2 tests.
If I change the values in the methods so that the tests fail, I get this result:
Ran 5 tests in 0.017s
FAILED (failures=2)
The failed tests are the methods test_positive
and test_negative
.
But, which are the other tests?
Added later
In the same Notebook there is another cell, containing another TestCase object with its own 3 methods.