feat: 修改ui用例的报告路径
This commit is contained in:
@@ -1,14 +1,60 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
tests_dir = Path(__file__).resolve().parent
|
||||
project_root = tests_dir.parent
|
||||
CURRENT_FILE_PATH = Path(__file__).resolve()
|
||||
PROJECT_ROOT = CURRENT_FILE_PATH.parent.parent
|
||||
ALLURE_RESULTS_DIR = PROJECT_ROOT / "allure-results"
|
||||
ALLURE_REPORT_DIR = PROJECT_ROOT / "allure-report"
|
||||
LOCAL_ALLURE_PATH = PROJECT_ROOT / "allure" / "allure-2.28.0" / "bin" / "allure.bat"
|
||||
|
||||
command = [sys.executable, "-m", "pytest", str(tests_dir), *sys.argv[1:]]
|
||||
completed = subprocess.run(command, cwd=project_root)
|
||||
|
||||
def _has_alluredir_arg(args: list[str]) -> bool:
|
||||
return any(arg == "--alluredir" or arg.startswith("--alluredir=") for arg in args)
|
||||
|
||||
|
||||
def _allure_command() -> str | None:
|
||||
env_allure_path = os.environ.get("ALLURE_PATH")
|
||||
if env_allure_path:
|
||||
return env_allure_path
|
||||
|
||||
if LOCAL_ALLURE_PATH.exists():
|
||||
return str(LOCAL_ALLURE_PATH)
|
||||
|
||||
return shutil.which("allure")
|
||||
|
||||
|
||||
def _generate_allure_report() -> None:
|
||||
allure = _allure_command()
|
||||
if not allure:
|
||||
print("未找到 allure 命令,跳过 HTML 报告生成。")
|
||||
return
|
||||
|
||||
command = [
|
||||
allure,
|
||||
"generate",
|
||||
str(ALLURE_RESULTS_DIR),
|
||||
"-o",
|
||||
str(ALLURE_REPORT_DIR),
|
||||
"--clean",
|
||||
]
|
||||
subprocess.run(command, cwd=PROJECT_ROOT, check=False)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
tests_dir = CURRENT_FILE_PATH.parent
|
||||
pytest_args = sys.argv[1:]
|
||||
|
||||
command = [sys.executable, "-m", "pytest", str(tests_dir)]
|
||||
if not _has_alluredir_arg(pytest_args):
|
||||
command.append(f"--alluredir={ALLURE_RESULTS_DIR}")
|
||||
command.extend(pytest_args)
|
||||
|
||||
completed = subprocess.run(command, cwd=PROJECT_ROOT)
|
||||
_generate_allure_report()
|
||||
return completed.returncode
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user