cli.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import os, sys
  4. from allure_combine import combine_allure
  5. def run():
  6. # 获取 python运行参数
  7. # 读取命令行传入的参数
  8. pytest_cmd_config = []
  9. for arg in sys.argv:
  10. if arg.startswith("-"):
  11. pytest_cmd_config.append(arg)
  12. # 2. 构建pytest参数
  13. pytest_args = ["-v", "-s", "--capture=sys","--clean-alluredir","--alluredir=allure-results",os.path.join(os.path.dirname(__file__), "apirun/core/ApiTestRunner.py")]
  14. pytest_args.extend(pytest_cmd_config)
  15. os.system(r"allure generate -c -o allure-report")
  16. combine_allure(r"./allure-report")
  17. if __name__ == '__main__':
  18. pytest_args = ["-v", "-s", "--capture=sys", '-n=1',
  19. "./apirun/core/ApiTestRunner.py",
  20. "--clean-alluredir",
  21. "--alluredir=allure-results",
  22. # "--type=yaml",
  23. # r"--cases=./examples/examples-ds"
  24. "--type=excel",
  25. r"--cases=./examples/examples-dsw"
  26. ]
  27. pytest.main(pytest_args)
  28. # TODO 代码参考如下:生成allure测试报告
  29. os.system(r"allure generate -c -o allure-report") # 等于你在命令行里面执行 allure
  30. # TODO 3: 代码参考如下:生成allure测试报告,双击打开直接查看 combine_allure(测试报告的路径)
  31. combine_allure(r"./allure-report")