forked from DxvLwRYF/apiAutoTest
增加eval`` 语法糖,可在用例中书写,内部会使用eval函数处理``中间的表达式内容,会优先处理&$.uid&类似的jsonpath语法糖
This commit is contained in:
parent
9706f6cd1d
commit
b6ddb1df9e
|
@ -140,6 +140,10 @@ https://www.bilibili.com/video/BV1EE411B7SU?p=10
|
|||
> 详细内容见代码注释`tools/data_clearing.py`
|
||||
> 如不需要使用该功能请做如下处理,如也不使用数据库对象,只需参考 https://gitee.com/zy7y/apiAutoTest/issues/I2BAQL 修改即可
|
||||

|
||||
|
||||
2021/01/27 添加eval语法糖,请求数据需要上个接口返回的id+1,实现基本的数学预算,使用形式具体查看excel用例文件及用例描述页,与报告对着看
|
||||
|
||||

|
||||
#### 博客园首发
|
||||
https://www.cnblogs.com/zy7y/p/13426816.html
|
||||
|
||||
|
|
Binary file not shown.
|
@ -40,6 +40,9 @@ def rep_expr(content: str, data: dict, expr: str = '&(.*?)&') -> str:
|
|||
"""
|
||||
for ctt in re.findall(expr, content):
|
||||
content = content.replace(f'&{ctt}&', str(extractor(data, ctt)))
|
||||
# 解决运算问题,实现+ -等常规数学运算, 用例书写格式{"uid":eval`&$.pid&+1`} 如果需要是字符串{"uid":eval`&$.pid&+1`}
|
||||
for e in re.findall('eval`(.*)`', content):
|
||||
content = content.replace(f'eval`{e}`', str(eval(e)))
|
||||
return content
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue