◐ Shell
clean mode source ↗

Message 352882 - Python tracker

+1 for the feature

Subtests make the test results of all asserts visible at test execution time but decrease the readability of a test:

@parameterized([2,4,6])
def test_method_whenCalled_returnsNone(self, a):
    # 1) arrange
    something = Something()

    # 2) act
    result = something.method(a)

    # 3) assert
    self.assertIsNone(result)

When using subtests the phases of 1) arrange, 2) act, 3) assert are not clearly separated, the unit test contains logic and two additional indentation levels that could be avoided with parameterized tests:

def test_method_whenCalled_returnsNone(self, a):
    # 1) arrange
    something = Something()

    for a in [2,4,6]:
        with self.subTest(a=a):
            # 2) act
            result = something.method(a)

            # 3) assert
            self.assertIsNone(result)