Python docs say give this example of using a subTest in unit testing:
import unittest
class NumbersTest(unittest.TestCase):
def test_even(self):
"""
Test that numbers between 0 and 5 are all even.
"""
for i in range(0, 6):
with self.subTest(i=i):
self.assertEqual(i % 2, 0)
This runs all 5 tests (i=0..5) before producing output for all 5 failures.
How can I print about the failures along the way (say in the for loop after the with block)?
I only need the answer for Python 3.
In my test, I have thousands of subtests and it can take many minutes to finish. I want to know if it's already failed as I'm watching it.