debugtalk.py文件

httprunner约定大于配置,debugtalk.py文件在项目根目录下,httprunner基于项目根目录使用相对路径,该文件中定义的函数,在用例中可以直接使用${funcname}进行引用,既减少了配置文件步骤,又能对用例做很好的扩展,了解更多内容参考https://debugtalk.com/post/apitestengine-hot-plugin/

场景:根据用例的运行时间定义文档的名称
解决:在debugtalk.py文件中定义获取当前时间的函数,用例中的文档名使用参数引用该函数

debugtalk.py

  1. import time
  2. def get_time():
  3. return str(int(time.time()*1000))

testcases/change_doc.yml

  1. name: change title
  2. variables:
  3. doc_name: demo_${get_time()} # 引用debugtalk.py中定义的方法
  4. verify: false
  5. teststeps:
  6. - name:xxx
  7. .....

用例中可以使用前置方法和后置方法

pytest对比httprunner

pytest httprunner 作用
steup_class config中的setup_hooks 整个用例执行前运行
teardown_class config中的teardown_hooks 整个用例执行完后运行
setup teststeps中的setup_hooks 单个步骤执行前运行
teartown teststeps中的teardown_hooks 单个步骤执行完后运行