我正在开发一种使用pytest框架自动化一些测试用例的设计。我正在使用YAML文件格式来传递每个测试用例的输入参数。每个测试用例可以调用一个或多个库级方法。每个库方法可以依次调用多个库方法。在这里,我需要传递内部库调用所需的许多参数。有没有更好的方法可以用于以下设计?
input.yaml文件采用每个测试用例的输入参数。测试用例调用库API,并且此API可以调用许多其他API以从不同的错误情况中恢复。目前,我正在考虑从input.yaml中传递所有必需的参数。
input.yaml
testcases:
testcase1:
param1: value1
param2: value2
paramN: valueN
testsuite.py
def test_testcase1(self, **kwargs):
libApi(force=True, **kwargs)
lib.py
def libApi(force=False, **kwargs):
if force:
try:
api(**kwargs)
except CustomException1:
api1(**kwargs)
api4(**kwargs)
except CustomException2:
api2(**kwargs)
api3(**kwargs)
except CustomExceptionN:
apiN(**kwargs)
else:
api(**kwargs)
在上面的代码片段中,当force=True
时,可能会调用许多api()
,我需要从input.yaml中传递所有这些API所需的所有参数,因为我不知道哪个错误条件发生。有没有更好的设计方法?