代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import pytest
import sys
import subprocess
from utils.log_recorder import log
from common.path_handler import TEST_CASES, HTML_REPORT_FILE, ALLURE_REPORT, ALLURE_RESULT
import warnings
from urllib3.exceptions import NotOpenSSLWarning
warnings.filterwarnings('ignore', category=NotOpenSSLWarning)
WIN = sys.platform.startswith('win')
def run_tests():
"""
运行测试并生成报告的函数。
"""
# 定义一些常用参数,可以根据实际情况调整
pytest_args = [
'--verbose', # 增加详细程度
f'--html={HTML_REPORT_FILE}', # 生成 html 报告
f'--alluredir={ALLURE_RESULT}', # 生成 allure 报告目录
'--clean-alluredir', # 清空 allure 报告目录
# '-m "important"', # 运行用 @pytest.mark.important 标记的测试
# '-k "specific_test_function"', # 根据关键字运行特定测试
'--maxfail=3' # 在出现 3 个失败测试后停止执行
]
try:
# 运行 pytest 测试
pytest.main(pytest_args + [TEST_CASES])
log.info("Pytest tests executed successfully.")
allure_commands = [
f"allure generate {ALLURE_RESULT} -c -o {ALLURE_REPORT}",
f"allure open {ALLURE_REPORT}"
]
for cmd in allure_commands:
full_cmd = "call " + cmd if WIN else cmd
subprocess.run(full_cmd, shell=True)
log.info(f"{cmd} executed successfully.")
except Exception as e:
log.error(f"Error occurred during test execution: {e}")
if __name__ == "__main__":
run_tests()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。