Q: httprunner3.x 数据驱动,无法更新数据问题?
A: 1) 如何解决呢?
a. httprunner.utils.merge_variables,(单step用例该问题解决,会影响多step用例获取钱pre step的参数,不推荐)
注释httprunner/utils.py:210
b. httprunner.runner.HttpRunner.run_testcase(单step用例该问题解决,不会影响多step用例获取钱pre step的参数,但是多step依然会有这个问题)
for step in self.__teststeps:
# override variables
# step variables > extracted variables from previous steps
if len(self.__teststeps) <= 1:
step.variables.clear()
step.variables = merge_variables(step.variables, extracted_variables)
# step variables > testcase config variables
step.variables = merge_variables(step.variables, self.__config.variables)
c. 重写这部分方法
2)疑问? 这个问题应该是ddt没有办法规避,在google或者baidu没有找到相关案例
3)问题原因推测:
pytest与httprunner不兼容导致,
对于数据驱动httprunner,会将整个用例看做一个case suite,形成一个steps,
第二个case执行时会保留上一个case的用例的返回参数,
在merge的时候会优先保留上个step返回的参数进行update,
httprunner.runner.HttpRunner.run_testcase
# run teststeps
for step in self.__teststeps:
# override variables
# step variables > extracted variables from previous steps
step.variables = merge_variablxzes(step.variables, extracted_variables)
# step variables > testcase config variables
step.variables = merge_variables(step.variables, self.__config.variables)
其中merge_variables调用两次用来更新一个相同的变量,进一步去看下这个方法的作用域
def merge_variables(
variables: VariablesMapping, variables_to_be_overridden: VariablesMapping
) -> VariablesMapping:
""" merge two variables mapping, the first variables have higher priority
"""
step_new_variables = {}
for key, value in variables.items():
print(f"${key}", key)
if f"${key}" == value or "${" + key + "}" == value:
# e.g. {"base_url": "$base_url"}
# or {"base_url": "${base_url}"}
continue
step_new_variables[key] = value
merged_variables = copy.copy(variables_to_be_overridden)
merged_variables.update(step_new_variables)
return merged_variables
-----
Q: pytest 数据驱动用例没有办法进行locust压测,locust无法读取$变量中的值
A: 也是和locust兼容问题,时间原因暂未解
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。