subtests are a light alternative to parametered tests as in issue7897. They don't generate the tests for you, they simply allow to partition a given test case in several logical units. Meaning, when a subtest fails, the other subtests in the test will still run (and the failures will print their respective parameters).
Concretely, running the follow example:
class MyTest(unittest.TestCase):
def test_b(self):
"""some test"""
for i in range(2, 5):
for j in range(0, 3):
with self.subTest(i=i, j=j):
self.assertNotEqual(i % 3, j)
will give the following output:
======================================================================
FAIL: test_b (__main__.MyTest) (i=2, j=2)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 2 == 2
======================================================================
FAIL: test_b (__main__.MyTest) (i=3, j=0)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 0 == 0
======================================================================
FAIL: test_b (__main__.MyTest) (i=4, j=1)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 1 == 1
----------------------------------------------------------------------