refactor(tests): restructure into layered POM architecture with Allure reporting
- Split framework into core/ (config, logger, db, driver factories, screenshot, allure integration) and pages/ (PO layer: base/admin/driver); flatten test files per platform (web/admin, app/driver_android, cross_end) - Slim root conftest.py 656 -> ~100 lines: drop inline CN HTML report, add Allure severity mapping (p0/p1/p2 -> blocker/normal/minor) and environment.properties; support both tests.*-prefixed and bare imports - Preserve TC-D2S-001/002 cross-end E2E cases with business logic unchanged, add allure epic/feature/story/step annotations - Deduplicate: single makereport hook, shared failure-screenshot helpers, single SCREENSHOTS_DIR constant; deterministic auth-state role loading - Move DB credentials from db_helper.py into test_config.yaml (database section) - Move pytest.ini to repo root; switch reporting to allure-pytest (drop pytest-html/junitxml); update requirements.txt accordingly - Delete deprecated scaffolding: test_freight_full_flow + 6 stale page objects, iOS/shipper empty shells, dead utils - Fix flaky vxe-table action-row wait: wait for a visible td instead of hidden placeholder rows (fixed shipper-payment timeouts) - Verified end-to-end against live env: both E2E cases pass (2 passed 3m12s); run artifacts (logs/screenshots/allure) included per repo convention
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""统一日志工具。
|
||||
|
||||
Usage:
|
||||
from tests.core.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger.info("开始执行用例")
|
||||
logger.error(f"用例失败: {e}")
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
from tests.core.paths import LOGS_DIR
|
||||
|
||||
LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 日志格式
|
||||
_FORMAT = "%(asctime)s [%(levelname)s] %(name)s — %(message)s"
|
||||
_DATE_FMT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
# 根 logger 配置(模块级,只初始化一次)
|
||||
_ROOT_LOGGER = logging.getLogger("tests")
|
||||
_ROOT_LOGGER.setLevel(logging.DEBUG)
|
||||
|
||||
# 控制台 Handler
|
||||
_console_handler = logging.StreamHandler(sys.stdout)
|
||||
_console_handler.setLevel(logging.INFO)
|
||||
_console_handler.setFormatter(logging.Formatter(_FORMAT, datefmt=_DATE_FMT))
|
||||
|
||||
# 文件 Handler(每次运行一个日志文件)
|
||||
_log_file = LOGS_DIR / f"test_run_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
||||
_file_handler = logging.FileHandler(_log_file, encoding="utf-8")
|
||||
_file_handler.setLevel(logging.DEBUG)
|
||||
_file_handler.setFormatter(logging.Formatter(_FORMAT, datefmt=_DATE_FMT))
|
||||
|
||||
_ROOT_LOGGER.addHandler(_console_handler)
|
||||
_ROOT_LOGGER.addHandler(_file_handler)
|
||||
|
||||
|
||||
def get_logger(name: str) -> logging.Logger:
|
||||
"""获取以 `tests.` 为前缀的子 logger。"""
|
||||
if not name.startswith("tests."):
|
||||
name = f"tests.{name}"
|
||||
return logging.getLogger(name)
|
||||
Reference in New Issue
Block a user