1 Star 17 Fork 3

CodeRex/ApiAutoTest-pytest

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
run.py 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
CodeRex 提交于 2024-10-08 14:39 +08:00 . push代码
#!/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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/CodeRex/ApiAutoTest-pytest.git
git@gitee.com:CodeRex/ApiAutoTest-pytest.git
CodeRex
ApiAutoTest-pytest
ApiAutoTest-pytest
master

搜索帮助