unittest_subtest
If you test multiple conditions within a single test function, rather than repeating code or writing a helper function that runs the same test code with different inputs each time, you can use the subtest
feature.
It will loop through each test case and run the same test sequence on each one.
unittest
will keep track of which subTest
fails and run the others even if one fails.
You can pass any arbitrary keyword args to subTest()
to give context. This allows the subtests to list error messages specific to the subtest case.
Last updated