During testing, I would like to visualise a running enumeration of the tests. Example code:
import unittest
from functions import function_a, function_b
class TestFunctions(unittest.TestCase):
counter = 0
def test_function_a(self):
self.counter += 1
print(f"\nTest {self.counter}: 'function_a'"
# some code to test function_a
print("\t...done!")
def test_function_b(self):
self.counter += 1
print(f"\nTest {self.counter}: 'function_b'"
# some code to test function_b
print("\t...done!")
if __name__ == "__main__":
unittest.main()
Expected output:
Test 1: 'function_a'
...done!
.
Test 2: 'function_b'
...done!
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
Actual output:
Test 1: 'function_a'
...done!
.
Test 1: 'function_b'
...done!
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
i.e., self.counter
gets updated once in each method call, but I guess then it's being re-initialised each time in between method calls.