Selaa lähdekoodia

网络不允许安装某些依赖,架构推翻

BrainZhang 1 kuukausi sitten
vanhempi
sitoutus
2c2f09a758

+ 0 - 0
Tests/OTHER/__init__.py


+ 45 - 0
Tests/OTHER/test_example.py

@@ -0,0 +1,45 @@
+# tests/test_example.py
+
+import pytest
+import time
+
+
+class TestExample:
+    """示例测试类"""
+
+    def test_addition(self):
+        """测试加法运算"""
+        assert 1 + 1 == 2
+
+    def test_subtraction(self):
+        """测试减法运算"""
+        assert 5 - 3 == 2
+
+    def test_failure_example(self):
+        """这是一个会失败的测试示例"""
+        assert 5 == 6, "数字不相等"
+
+    @pytest.mark.skip(reason="示例跳过测试")
+    def test_skip_example(self):
+        """这是一个跳过的测试示例"""
+        assert True
+
+
+class TestWebExample:
+    """Web 测试示例"""
+
+    def test_web_title(self, driver):
+        """测试网页标题"""
+        driver.get("https://baidu.com")
+        assert "Example" in driver.title
+
+    def test_web_content(self, driver):
+        """测试网页内容"""
+        driver.get("https://baidu.com")
+        content = driver.find_element_by_tag_name("body").text
+        assert "example" in content.lower()
+
+    def test_chinese_content(self):
+        """测试中文字符"""
+        chinese_text = "这是一段中文测试文本"
+        assert "中文" in chinese_text

+ 0 - 0
Tests/UI/__init__.py


+ 2 - 2
requirements.txt

@@ -6,9 +6,9 @@ selenium
 requests
 # 测试框架
 pytest
-pytest-html
+pytest-html            # 实在没有办法,才使用pytest自带报告,自定义CSS,JS实现现代化
 # 报告依赖
-allure-pytest
+# allure-pytest        废弃,网络环境不允许
 # 其他依赖
 Pillow
 pyyaml

+ 0 - 82
templates/allure/custom.css

@@ -1,82 +0,0 @@
-/* Allure报告自定义样式 */
-.hero__title {
-    color: #2c3e50;
-    font-size: 2.5rem;
-    font-weight: 700;
-}
-
-.hero__subtitle {
-    color: #7f8c8d;
-    font-size: 1.2rem;
-}
-
-.status-button--passed {
-    background-color: #27ae60;
-    border-color: #27ae60;
-}
-
-.status-button--failed {
-    background-color: #e74c3c;
-    border-color: #e74c3c;
-}
-
-.status-button--broken {
-    background-color: #f39c12;
-    border-color: #f39c12;
-}
-
-.status-button--skipped {
-    background-color: #95a5a6;
-    border-color: #95a5a6;
-}
-
-.timeline__item--selected {
-    border-color: #3498db;
-}
-
-.widget__title {
-    color: #2c3e50;
-    border-bottom: 2px solid #3498db;
-    padding-bottom: 10px;
-}
-
-.test-case__header {
-    background-color: #ecf0f1;
-    padding: 15px;
-    border-radius: 5px;
-    margin-bottom: 15px;
-}
-
-.step__title {
-    color: #2c3e50;
-    font-weight: 600;
-}
-
-.attachment__text {
-    background-color: #f8f9fa;
-    border: 1px solid #dee2e6;
-    border-radius: 5px;
-    padding: 15px;
-    font-family: 'Courier New', monospace;
-    font-size: 0.9rem;
-}
-
-/* 深色模式支持 */
-@media (prefers-color-scheme: dark) {
-    :root {
-        --color-background: #2c3e50;
-        --color-text: #ecf0f1;
-        --color-border: #34495e;
-    }
-
-    .test-case__header {
-        background-color: #34495e;
-        color: #ecf0f1;
-    }
-
-    .attachment__text {
-        background-color: #2c3e50;
-        border-color: #34495e;
-        color: #ecf0f1;
-    }
-}

+ 0 - 172
templates/email/report_template.html

@@ -1,172 +0,0 @@
-<!DOCTYPE html>
-<html lang="zh-CN">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>API测试报告 - {{ report_date }}</title>
-    <style>
-        body {
-            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
-            line-height: 1.6;
-            color: #333;
-            max-width: 100%;
-            margin: 0;
-            padding: 20px;
-        }
-        .container {
-            max-width: 800px;
-            margin: 0 auto;
-            background: #fff;
-            border-radius: 8px;
-            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
-            overflow: hidden;
-        }
-        .header {
-            background: linear-gradient(135deg, #3498db, #2980b9);
-            color: white;
-            padding: 30px;
-            text-align: center;
-        }
-        .header h1 {
-            margin: 0;
-            font-size: 28px;
-        }
-        .header p {
-            margin: 10px 0 0;
-            opacity: 0.9;
-        }
-        .content {
-            padding: 30px;
-        }
-        .stats {
-            display: flex;
-            justify-content: space-around;
-            margin-bottom: 30px;
-            flex-wrap: wrap;
-        }
-        .stat {
-            text-align: center;
-            padding: 20px;
-            border-radius: 8px;
-            color: white;
-            min-width: 120px;
-            margin: 10px;
-        }
-        .stat.passed {
-            background: linear-gradient(135deg, #27ae60, #2ecc71);
-        }
-        .stat.failed {
-            background: linear-gradient(135deg, #e74c3c, #e67e22);
-        }
-        .stat.skipped {
-            background: linear-gradient(135deg, #95a5a6, #7f8c8d);
-        }
-        .stat.total {
-            background: linear-gradient(135deg, #3498db, #2980b9);
-        }
-        .stat .number {
-            font-size: 32px;
-            font-weight: bold;
-            display: block;
-        }
-        .stat .label {
-            font-size: 14px;
-            opacity: 0.9;
-        }
-        .summary {
-            background: #f8f9fa;
-            padding: 20px;
-            border-radius: 8px;
-            margin-bottom: 20px;
-        }
-        .test-case {
-            border-left: 4px solid #dee2e6;
-            padding: 15px;
-            margin-bottom: 15px;
-            background: #f8f9fa;
-            border-radius: 4px;
-        }
-        .test-case.passed {
-            border-left-color: #27ae60;
-        }
-        .test-case.failed {
-            border-left-color: #e74c3c;
-        }
-        .test-case.skipped {
-            border-left-color: #f39c12;
-        }
-        .footer {
-            text-align: center;
-            padding: 20px;
-            background: #f8f9fa;
-            color: #6c757d;
-            font-size: 14px;
-        }
-        .btn {
-            display: inline-block;
-            padding: 10px 20px;
-            background: #3498db;
-            color: white;
-            text-decoration: none;
-            border-radius: 4px;
-            margin-top: 20px;
-        }
-    </style>
-</head>
-<body>
-    <div class="container">
-        <div class="header">
-            <h1>API测试报告</h1>
-            <p>生成时间: {{ report_time }}{% if environment %} | 环境: {{ environment }}{% endif %}</p>
-        </div>
-
-        <div class="content">
-            <div class="stats">
-                <div class="stat passed">
-                    <span class="number">{{ summary.passed }}</span>
-                    <span class="label">通过</span>
-                </div>
-                <div class="stat failed">
-                    <span class="number">{{ summary.failed }}</span>
-                    <span class="label">失败</span>
-                </div>
-                <div class="stat skipped">
-                    <span class="number">{{ summary.skipped }}</span>
-                    <span class="label">跳过</span>
-                </div>
-                <div class="stat total">
-                    <span class="number">{{ summary.total }}</span>
-                    <span class="label">总计</span>
-                </div>
-            </div>
-
-            <div class="summary">
-                <h3>测试概要</h3>
-                <p>成功率: <strong>{{ summary.success_rate }}%</strong></p>
-                <p>总耗时: <strong>{{ summary.duration }}</strong></p>
-            </div>
-
-            <h3>测试用例详情</h3>
-            {% for test in tests %}
-            <div class="test-case {{ test.status }}">
-                <strong>{{ test.name }}</strong>
-                <div>状态: {{ test.status|upper }} | 耗时: {{ test.duration }}</div>
-                {% if test.error %}
-                <div style="margin-top: 10px; color: #e74c3c;">
-                    <strong>错误信息:</strong> {{ test.error }}
-                </div>
-                {% endif %}
-            </div>
-            {% endfor %}
-
-            <div style="text-align: center;">
-                <a href="{{ report_url }}" class="btn">查看完整报告</a>
-            </div>
-        </div>
-
-        <div class="footer">
-            <p>&copy; 2024 API自动化测试平台. 本邮件由系统自动生成,请勿直接回复。</p>
-        </div>
-    </div>
-</body>
-</html>

+ 0 - 57
templates/html/base.html

@@ -1,57 +0,0 @@
-<!DOCTYPE html>
-<html lang="zh-CN">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>{% block title %}API测试报告{% endblock %}</title>
-    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
-    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.0/font/bootstrap-icons.css" rel="stylesheet">
-    <link rel="stylesheet" href="style.css">
-    {% block extra_css %}{% endblock %}
-</head>
-<body>
-    {% include 'header.html' %}
-
-    <div class="container-fluid">
-        <div class="row">
-            <nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
-                <div class="position-sticky pt-3">
-                    <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
-                        <span>测试概览</span>
-                    </h6>
-                    <ul class="nav flex-column">
-                        <li class="nav-item">
-                            <a class="nav-link active" href="#summary">
-                                <i class="bi bi-speedometer2"></i>
-                                总体统计
-                            </a>
-                        </li>
-                        <li class="nav-item">
-                            <a class="nav-link" href="#test-cases">
-                                <i class="bi bi-list-check"></i>
-                                测试用例
-                            </a>
-                        </li>
-                        <li class="nav-item">
-                            <a class="nav-link" href="#charts">
-                                <i class="bi bi-bar-chart"></i>
-                                图表分析
-                            </a>
-                        </li>
-                    </ul>
-                </div>
-            </nav>
-
-            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
-                {% block content %}{% endblock %}
-            </main>
-        </div>
-    </div>
-
-    {% include 'footer.html' %}
-
-    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
-    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
-    {% block extra_js %}{% endblock %}
-</body>
-</html>

+ 0 - 8
templates/html/footer.html

@@ -1,8 +0,0 @@
-<footer class="footer mt-auto py-3 bg-light">
-    <div class="container">
-        <span class="text-muted">
-            &copy; 2024 API自动化测试平台. 生成于 {{ report_time }}.
-            {% if environment %}环境: {{ environment }}{% endif %}
-        </span>
-    </div>
-</footer>

+ 0 - 18
templates/html/header.html

@@ -1,18 +0,0 @@
-<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
-    <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">
-        <i class="bi bi-speedometer2"></i>
-        API测试报告
-    </a>
-    <button class="navbar-toggler position-absolute d-md-none collapsed" type="button"
-            data-bs-toggle="collapse" data-bs-target="#sidebar"
-            aria-controls="sidebar" aria-expanded="false" aria-label="Toggle navigation">
-        <span class="navbar-toggler-icon"></span>
-    </button>
-    <div class="navbar-nav">
-        <div class="nav-item text-nowrap">
-            <span class="nav-link px-3 text-white">
-                生成时间: {{ report_time }}
-            </span>
-        </div>
-    </div>
-</header>

+ 0 - 140
templates/html/index.html

@@ -1,140 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}API测试报告 - {{ report_time }}{% endblock %}
-
-{% block content %}
-<div id="summary" class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
-    <h1 class="h2">测试报告概览</h1>
-    <div class="btn-toolbar mb-2 mb-md-0">
-        <div class="btn-group me-2">
-            <button type="button" class="btn btn-sm btn-outline-secondary">导出PDF</button>
-            <button type="button" class="btn btn-sm btn-outline-secondary">发送邮件</button>
-        </div>
-    </div>
-</div>
-
-<div class="row">
-    <div class="col-md-3">
-        <div class="stats-card passed">
-            <div class="number">{{ summary.passed }}</div>
-            <div class="label">通过</div>
-        </div>
-    </div>
-    <div class="col-md-3">
-        <div class="stats-card failed">
-            <div class="number">{{ summary.failed }}</div>
-            <div class="label">失败</div>
-        </div>
-    </div>
-    <div class="col-md-3">
-        <div class="stats-card skipped">
-            <div class="number">{{ summary.skipped }}</div>
-            <div class="label">跳过</div>
-        </div>
-    </div>
-    <div class="col-md-3">
-        <div class="stats-card total">
-            <div class="number">{{ summary.total }}</div>
-            <div class="label">总计</div>
-        </div>
-    </div>
-</div>
-
-<div class="row mt-4">
-    <div class="col-md-6">
-        <div class="card">
-            <div class="card-header">
-                <h5 class="card-title">测试统计</h5>
-            </div>
-            <div class="card-body">
-                <canvas id="testChart" width="400" height="200"></canvas>
-            </div>
-        </div>
-    </div>
-    <div class="col-md-6">
-        <div class="card">
-            <div class="card-header">
-                <h5 class="card-title">执行信息</h5>
-            </div>
-            <div class="card-body">
-                <table class="table table-sm">
-                    <tr>
-                        <th>生成时间:</th>
-                        <td>{{ report_time }}</td>
-                    </tr>
-                    <tr>
-                        <th>测试环境:</th>
-                        <td>{{ environment or '未指定' }}</td>
-                    </tr>
-                    <tr>
-                        <th>总耗时:</th>
-                        <td>{{ summary.duration }}</td>
-                    </tr>
-                    <tr>
-                        <th>成功率:</th>
-                        <td>{{ summary.success_rate }}%</td>
-                    </tr>
-                </table>
-            </div>
-        </div>
-    </div>
-</div>
-
-<div id="test-cases" class="mt-5">
-    <h2 class="h4 mb-3">测试用例详情</h2>
-    
-    {% for test in tests %}
-    <div class="test-case {{ test.status }}">
-        <div class="test-name">{{ test.name }}</div>
-        <div class="test-duration">耗时: {{ test.duration }}</div>
-        <span class="badge bg-{% if test.status == 'passed' %}success{% elif test.status == 'failed' %}danger{% else %}warning{% endif %}">
-            {{ test.status|upper }}
-        </span>
-        
-        {% if test.error %}
-        <div class="mt-2">
-            <button class="btn btn-sm btn-outline-danger" type="button" data-bs-toggle="collapse" 
-                    data-bs-target="#error-{{ loop.index }}" aria-expanded="false">
-                查看错误详情
-            </button>
-            <div class="collapse mt-2" id="error-{{ loop.index }}">
-                <div class="card card-body">
-                    <pre class="mb-0">{{ test.error }}</pre>
-                </div>
-            </div>
-        </div>
-        {% endif %}
-    </div>
-    {% endfor %}
-</div>
-{% endblock %}
-
-{% block extra_js %}
-<script>
-// 测试统计图表
-var ctx = document.getElementById('testChart').getContext('2d');
-var testChart = new Chart(ctx, {
-    type: 'doughnut',
-    data: {
-        labels: ['通过', '失败', '跳过'],
-        datasets: [{
-            data: [{{ summary.passed }}, {{ summary.failed }}, {{ summary.skipped }}],
-            backgroundColor: [
-                '#27ae60',
-                '#e74c3c',
-                '#f39c12'
-            ],
-            borderWidth: 1
-        }]
-    },
-    options: {
-        responsive: true,
-        plugins: {
-            legend: {
-                position: 'bottom',
-            }
-        }
-    }
-});
-</script>
-{% endblock %}

+ 0 - 121
templates/html/style.css

@@ -1,121 +0,0 @@
-/* 自定义样式 */
-body {
-    font-size: .875rem;
-}
-
-.sidebar {
-    position: fixed;
-    top: 0;
-    bottom: 0;
-    left: 0;
-    z-index: 100;
-    padding: 48px 0 0;
-    box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
-}
-
-.sidebar-sticky {
-    position: relative;
-    top: 0;
-    height: calc(100vh - 48px);
-    padding-top: .5rem;
-    overflow-x: hidden;
-    overflow-y: auto;
-}
-
-.sidebar .nav-link {
-    font-weight: 500;
-    color: #333;
-}
-
-.sidebar .nav-link.active {
-    color: #007bff;
-}
-
-.sidebar-heading {
-    font-size: .75rem;
-    text-transform: uppercase;
-}
-
-/* 卡片样式 */
-.card {
-    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
-    margin-bottom: 1.5rem;
-}
-
-.card-header {
-    background-color: rgba(0, 0, 0, 0.03);
-    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
-}
-
-/* 统计卡片 */
-.stats-card {
-    text-align: center;
-    padding: 1.5rem;
-    border-radius: 0.5rem;
-    color: white;
-    margin-bottom: 1.5rem;
-}
-
-.stats-card.passed {
-    background: linear-gradient(45deg, #27ae60, #2ecc71);
-}
-
-.stats-card.failed {
-    background: linear-gradient(45deg, #e74c3c, #e67e22);
-}
-
-.stats-card.skipped {
-    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
-}
-
-.stats-card.total {
-    background: linear-gradient(45deg, #3498db, #2980b9);
-}
-
-.stats-card .number {
-    font-size: 2.5rem;
-    font-weight: bold;
-}
-
-.stats-card .label {
-    font-size: 1rem;
-    opacity: 0.9;
-}
-
-/* 测试用例列表 */
-.test-case {
-    border-left: 4px solid #dee2e6;
-    padding: 1rem;
-    margin-bottom: 1rem;
-    border-radius: 0.25rem;
-    background-color: #f8f9fa;
-}
-
-.test-case.passed {
-    border-left-color: #27ae60;
-}
-
-.test-case.failed {
-    border-left-color: #e74c3c;
-}
-
-.test-case.skipped {
-    border-left-color: #f39c12;
-}
-
-.test-case .test-name {
-    font-weight: 600;
-    margin-bottom: 0.5rem;
-}
-
-.test-case .test-duration {
-    color: #6c757d;
-    font-size: 0.875rem;
-}
-
-/* 响应式调整 */
-@media (max-width: 767.98px) {
-    .sidebar {
-        top: 5rem;
-    }
-}

+ 52 - 213
testRun.py

@@ -1,227 +1,66 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-"""
-测试运行脚本
-用于执行项目中的接口测试用例并生成测试报告
-
-使用方法:
-1. 直接运行: python testRun.py
-2. 带参数运行: python testRun.py -m "baidu" -e dev -r allure
-"""
-
 import os
-import sys
-import time
-import argparse
 import subprocess
-import webbrowser
-import json
-import shutil
-from datetime import datetime
+import sys
+from Utils.enhance_report import enhance_report
 
-# 添加项目根目录到Python路径,确保可以导入项目模块
+# 添加项目根目录到 Python 路径
 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
 
-def run_tests(test_marker=None, environment=None, report_type="allure"):
-    """
-    运行测试并生成报告
-    Args:
-        test_marker (str): pytest标记,用于选择特定测试
-        environment (str): 测试环境
-        report_type (str): 报告类型,支持html和allure
-    """
-    # 设置环境变量
-    if environment:
-        os.environ['TEST_ENV'] = environment
-        print(f"设置测试环境: {environment}")
 
+def run_tests():
+    """运行测试并生成美化报告"""
     # 创建报告目录
-    report_dir = os.path.join(os.path.dirname(__file__), 'Reports/API/')
-    if not os.path.exists(report_dir):
-        os.makedirs(report_dir)
+    os.makedirs('reports', exist_ok=True)
+    os.makedirs('reports/assets/screenshots', exist_ok=True)
+    os.makedirs('reports/assets/logs', exist_ok=True)
 
-    # 构建pytest命令
-    pytest_cmd = [
-        sys.executable, '-m', 'pytest',
-        'Tests/API/',  # 测试目录
-        '-v',  # 详细输出
-        '--tb=short',  # 短的traceback格式
-        '--alluredir', os.path.join(report_dir, 'allure_results')  # 总是生成Allure结果
-    ]
-
-    # 添加标记选择
-    if test_marker:
-        pytest_cmd.extend(['-m', test_marker])
-        print(f"运行标记为 '{test_marker}' 的测试")
-
-    # 记录开始时间
-    start_time = time.time()
-
-    # 运行测试
-    print("\n开始运行测试...")
-    print("命令: " + " ".join(pytest_cmd))
-    print("-" * 50)
+    print("开始运行测试...")
 
+    # 运行测试 - 使用UTF-8编码避免中文乱码
     try:
-        # 修复编码问题:使用subprocess.run并指定编码
-        result = subprocess.run(
-            pytest_cmd,
-            capture_output=True,
-            text=True,
-            encoding='utf-8',
-            errors='replace'
-        )
-
-        # 输出测试结果
-        print(result.stdout)
-        if result.stderr:
-            print("错误输出:")
-            print(result.stderr)
-
-        # 计算测试耗时
-        duration = time.time() - start_time
-        minutes, seconds = divmod(duration, 60)
-        print(f"\n测试完成,耗时: {int(minutes)}分{seconds:.2f}秒")
-
-        # 处理报告
-        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
-        report_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
-
-        if report_type == "html":
-            # 生成自定义HTML报告
-            html_report_dir = os.path.join(report_dir, f'html_report_{timestamp}')
-            os.makedirs(html_report_dir, exist_ok=True)
-
-            # 复制模板文件
-            templates_dir = os.path.join(os.path.dirname(__file__), 'templates', 'html')
-            for file in os.listdir(templates_dir):
-                if file.endswith('.html') or file.endswith('.css'):
-                    shutil.copy2(
-                        os.path.join(templates_dir, file),
-                        os.path.join(html_report_dir, file)
-                    )
-
-            # 生成测试数据JSON文件
-            generate_html_report_data(
-                result,
-                os.path.join(html_report_dir, 'data.json'),
-                report_time,
-                environment
-            )
-
-            print(f"HTML报告已生成: {html_report_dir}/index.html")
-
-        elif report_type == "allure":
-            # 生成Allure报告
-            allure_report_dir = os.path.join(report_dir, f'allure_report_{timestamp}')
-            allure_cmd = [
-                'allure', 'generate',
-                os.path.join(report_dir, 'allure_results'),
-                '-o', allure_report_dir,
-                '--clean'
-            ]
-            print(f"\n生成Allure报告: {' '.join(allure_cmd)}")
-            subprocess.run(allure_cmd, check=True)
-
-            # 复制自定义CSS
-            css_src = os.path.join(os.path.dirname(__file__), 'templates', 'allure', 'custom.css')
-            css_dest = os.path.join(allure_report_dir, 'plugins', 'custom-css', 'css', 'custom.css')
-            if os.path.exists(css_src):
-                os.makedirs(os.path.dirname(css_dest), exist_ok=True)
-                shutil.copy2(css_src, css_dest)
-
-            # 打开Allure报告
-            index_html = os.path.join(allure_report_dir, 'index.html')
-            if os.path.exists(index_html):
-                print(f"打开报告: {index_html}")
-                webbrowser.open(f'file://{os.path.abspath(index_html)}')
-
-        # 返回测试结果
-        return result.returncode
-
-    except (subprocess.CalledProcessError, FileNotFoundError) as e:
-        print(f"生成报告失败: {e}")
-        if "allure" in str(e):
-            print("请确保已安装Allure命令行工具")
-        return 1
+        result = subprocess.run([
+            'pytest',
+            'Tests/',
+            '--html=reports/report.html',
+            '--self-contained-html',
+            '-v'
+        ], capture_output=True, text=True, encoding='utf-8', errors='replace')
     except Exception as e:
-        print(f"运行测试时发生错误: {e}")
-        return 1
-
-
-def generate_html_report_data(result, output_path, report_time, environment):
-    """生成HTML报告所需的数据"""
-    # 解析测试结果(简化版)
-    # 在实际应用中,您可能需要解析pytest的JSON报告或Allure结果
-    summary = {
-        "total": 0,
-        "passed": 0,
-        "failed": 0,
-        "skipped": 0,
-        "duration": "0s",
-        "success_rate": 0
-    }
-
-    tests = []
-
-    # 这里只是示例,实际应用中需要解析真实的测试结果
-    # 您可以使用pytest-json-report插件来获取JSON格式的测试结果
-    summary["total"] = 2
-    summary["passed"] = 0
-    summary["failed"] = 2
-    summary["skipped"] = 0
-    summary["duration"] = "3.61s"
-    summary["success_rate"] = 0
-
-    tests.append({
-        "name": "TestBaiduAPI::test_baidu_search",
-        "status": "failed",
-        "duration": "2.1s",
-        "error": "AssertionError: assert 'python接口测试' in '<!DOCTYPE html>...'"
-    })
-
-    tests.append({
-        "name": "TestBaiduAPI::test_baidu_homepage",
-        "status": "failed",
-        "duration": "1.5s",
-        "error": "AssertionError: assert '百度一下' in '<!DOCTYPE html>...'"
-    })
-
-    # 保存数据到JSON文件
-    data = {
-        "summary": summary,
-        "tests": tests,
-        "report_time": report_time,
-        "environment": environment
-    }
-
-    with open(output_path, 'w', encoding='utf-8') as f:
-        json.dump(data, f, ensure_ascii=False, indent=2)
-
-
-def main():
-    """主函数,解析命令行参数并运行测试"""
-    # 创建参数解析器
-    parser = argparse.ArgumentParser(description='运行接口测试')
-    parser.add_argument('-m', '--marker', help='运行指定标记的测试,如 "baidu"')
-    parser.add_argument('-e', '--env', help='测试环境,如 "dev", "prod", "baidu"')
-    parser.add_argument('-r', '--report', choices=['html', 'allure'],
-                        default='allure', help='报告类型,默认allure')
-
-    # 解析参数
-    args = parser.parse_args()
-
-    # 运行测试
-    return_code = run_tests(
-        test_marker=args.marker,
-        environment=args.env,
-        report_type=args.report
-    )
-
-    # 退出码
-    sys.exit(return_code)
+        print(f"运行测试时出错: {e}")
+        # 尝试不使用编码参数
+        result = subprocess.run([
+            'pytest',
+            'Tests/',
+            '--html=reports/report.html',
+            '--self-contained-html',
+            '-v'
+        ], capture_output=True, text=True)
+
+    # 打印测试结果
+    print("\n测试输出:")
+    if result.stdout:
+        print(result.stdout)
+    if result.stderr:
+        print("错误输出:")
+        print(result.stderr)
+
+    # 增强报告
+    print("\n生成美化报告...")
+    if os.path.exists('reports/report.html'):
+        enhanced_report = enhance_report()
+        print(f"美化报告已生成: {enhanced_report}")
+    else:
+        print("警告: 未找到原始报告文件")
+        # 尝试直接运行增强报告
+        enhanced_report = enhance_report()
+        if enhanced_report:
+            print(f"美化报告已生成: {enhanced_report}")
+
+    # 返回退出码
+    return result.returncode
 
 
 if __name__ == '__main__':
-    main()
+    exit_code = run_tests()
+    print(f"\n测试执行完成,退出码: {exit_code}")
+    sys.exit(exit_code)