-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
66 lines (53 loc) · 1.67 KB
/
Copy pathrun.py
File metadata and controls
66 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest
import sys
import os
# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def run_all_tests():
"""运行所有测试并生成Allure报告"""
# 运行pytest并生成allure结果
pytest.main([
'testcases/',
'-v', # 详细输出
'-s', # 显示print输出
'--alluredir=reports/allure_results', # 生成allure原始数据
'--clean-alluredir', # 清理之前的allure结果
'--maxfail=1', # 失败1次就停止
])
# 生成allure报告(需要安装allure命令行工具)
# os.system('allure generate reports/allure_results -o reports/allure_report --clean')
# os.system('allure open reports/allure_report')
def run_specific_test(test_path):
"""运行指定测试"""
pytest.main([
test_path,
'-v',
'-s',
'--alluredir=reports/allure_results',
])
def generate_html_report():
"""生成HTML报告(不使用allure)"""
pytest.main([
'testcases/',
'--html=reports/test_report.html',
'--self-contained-html', # 独立HTML文件
])
if __name__ == '__main__':
print("=" * 50)
print("自动化测试框架")
print("=" * 50)
# 创建报告目录
os.makedirs('reports', exist_ok=True)
# 选择运行模式
if len(sys.argv) > 1:
if sys.argv[1] == 'html':
print("生成HTML报告...")
generate_html_report()
else:
print(f"运行指定测试: {sys.argv[1]}")
run_specific_test(sys.argv[1])
else:
print("运行所有测试...")
run_all_tests()