代码拉取完成,页面将自动刷新
import os
import shutil
import subprocess
def run_pytest_with_allure():
# 报告路径
result_dir = "reports"
report_dir = "allure-report"
# 清理旧报告
if os.path.exists(result_dir):
shutil.rmtree(result_dir)
if os.path.exists(report_dir):
shutil.rmtree(report_dir)
# 1. 运行 pytest 收集 allure 数据
print("---开始执行接口测试用例...")
ret = subprocess.call([
"pytest",
"testcases", # 或者指定单个文件 testcases/test_api.py
"--alluredir", result_dir
])
if ret != 0:
print("---用例执行有失败,请查看报告")
# 生成 html 报告
print("---生成 Allure 报告...")
subprocess.call([r"D:\allure-2.13.2\bin\allure.bat", "generate", result_dir, "-o", report_dir, "--clean"])
# 打开报告(可选)
print("---打开 Allure 报告...")
subprocess.call([r"D:\allure-2.13.2\bin\allure.bat", "open", report_dir])
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
run_pytest_with_allure()
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。