Python中的单元测试理论?

Ada*_*kin 5 python unit-testing junit-theory

在以前的生活中,我做了相当多的Java开发,并发现JUnit Theories非常有用.Python有没有类似的机制?

目前我做的事情如下:

def some_test(self):
    cases = [('some sample input', 'some expected value'),
            ('some other input', 'some other expected value')]

    for value, expected in cases:
        result = method_under_test(value)
        self.assertEqual(expected, result)
Run Code Online (Sandbox Code Playgroud)

但这是相当笨重的,如果第一个"案例"失败,其他所有案件都无法运行.

elb*_*ows 3

看起来 pytest 可以做这样的事情:https://docs.pytest.org/en/latest/parametrize.html

我自己还没有尝试过。