debugtalk.py文件
httprunner约定大于配置,debugtalk.py文件在项目根目录下,httprunner基于项目根目录使用相对路径,该文件中定义的函数,在用例中可以直接使用${funcname}进行引用,既减少了配置文件步骤,又能对用例做很好的扩展,了解更多内容参考https://debugtalk.com/post/apitestengine-hot-plugin/
场景:根据用例的运行时间定义文档的名称
解决:在debugtalk.py文件中定义获取当前时间的函数,用例中的文档名使用参数引用该函数
debugtalk.py
import time
def get_time():
return str(int(time.time()*1000))
testcases/change_doc.yml
name: change title
variables:
doc_name: demo_${get_time()} # 引用debugtalk.py中定义的方法
verify: false
teststeps:
- name:xxx
.....
用例中可以使用前置方法和后置方法
pytest对比httprunner
pytest | httprunner | 作用 |
---|---|---|
steup_class | config中的setup_hooks | 整个用例执行前运行 |
teardown_class | config中的teardown_hooks | 整个用例执行完后运行 |
setup | teststeps中的setup_hooks | 单个步骤执行前运行 |
teartown | teststeps中的teardown_hooks | 单个步骤执行完后运行 |