简体   繁体   English

在Python中运行参数测试

[英]Running parametric tests in Python

I usually keep my parametric tests as follow 我通常会按照以下方式进行参数测试

class ShouldCheckSomeCondition(unittest.TestCase):
  def __init__(self, parameters...):
    ...

  def runTest():
    # given
    ...

  cases = [(p1, ...), (p2, ...), ...]

Then build them at the bottom of the file and create a main to run them: 然后在文件底部构建它们,并创建一个主文件来运行它们:

def suite():
  test_suite = unittest.TestSuite()
  test_suite.add_tests([ShouldCheckSomeCondition(*params) for params in ShouldCheckSomeCondition.cases])
  return test_suite

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())

This is fine and all and I can run a single test file just fine. 一切都很好,我可以运行一个测试文件。 However, I can't make eg Nose to support this. 但是,我不能用鼻子来支持这一点。 Its discovery tries to build each case and fails. 它的发现尝试建立每种情况,但均失败。 The 'main' is ignored. “主”被忽略。 Does anyone have a good way to run many test files written in such manner? 有没有人可以很好地运行以这种方式编写的许多测试文件? Alternatively, are there other ways to nicely write parametric tests in python so that some test runner will handle it? 另外,还有其他方法可以在python中很好地编写参数测试,以便某些测试运行程序可以处理它吗?

因为您正在使用鼻子,所以我想看看参数化参数 ,这是鼻子参数化的延续

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM