ODS 完成
This commit is contained in:
@@ -1,50 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""测试命令仓库:集中维护 run_tests.py 的常用组合,并支持一键执行。
|
||||
|
||||
参数键说明(可在 PRESETS 中任意叠加):
|
||||
|
||||
1. suite
|
||||
类型:列表;值:["online"], ["offline"], ["integration"] 等。
|
||||
含义:引用 run_tests 内置测试套件。online=在线模式;offline=离线模式;integration=数据库集成测试。
|
||||
用法:["online","offline"] 表示一次执行两套;["integration"] 仅跑数据库相关用例。
|
||||
|
||||
2. tests
|
||||
类型:列表;示例:["tests/unit/test_config.py"]。
|
||||
含义:自定义的 pytest 目标路径,适合补充临时/个别测试。
|
||||
|
||||
3. mode
|
||||
类型:字符串;取值:"ONLINE" 或 "OFFLINE"。
|
||||
含义:覆盖 TEST_MODE;ONLINE 走 API 全流程,OFFLINE 读取 JSON 归档执行 Transform + Load。
|
||||
|
||||
4. db_dsn
|
||||
类型:字符串;示例:postgresql://user:pwd@host:5432/testdb。
|
||||
含义:设置 TEST_DB_DSN,使用真实 PostgreSQL 连接;不设置则使用伪 DB(仅记录操作,不落库)。
|
||||
|
||||
5. json_archive / json_temp
|
||||
类型:字符串;示例:"tests/testdata_json"、"C:/tmp/json"。
|
||||
含义:离线模式所需的归档输入目录 / 临时输出目录。未设置时沿用 .env 或默认配置。
|
||||
|
||||
6. keyword
|
||||
类型:字符串;示例:"ORDERS"。
|
||||
含义:等价 pytest -k,可筛选测试名/节点,只运行包含该关键字的用例。
|
||||
|
||||
7. pytest_args
|
||||
类型:字符串;示例:"-vv --maxfail=1"。
|
||||
含义:追加 pytest 命令行参数,用于控制日志、失败策略等。
|
||||
|
||||
8. env
|
||||
类型:列表;示例:["STORE_ID=123","API_TOKEN=xxx"]。
|
||||
含义:额外的环境变量,在调用 run_tests 前注入到 os.environ。
|
||||
|
||||
9. preset_meta
|
||||
类型:字符串;仅用于描述场景,不会传给 run_tests(纯注释)。
|
||||
|
||||
使用方式:
|
||||
- 直接 F5 或 `python scripts/test_presets.py`:读取 AUTO_RUN_PRESETS 的预置并顺序执行。
|
||||
- `python scripts/test_presets.py --preset offline_realdb`:临时指定要运行的组合。
|
||||
- `python scripts/test_presets.py --list`:查看参数说明及所有预置详情。
|
||||
"""
|
||||
|
||||
"""测试命令仓库:集中维护 run_tests.py 的常用组合,支持一键执行。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
@@ -55,46 +10,42 @@ from typing import List
|
||||
|
||||
RUN_TESTS_SCRIPT = os.path.join(os.path.dirname(__file__), "run_tests.py")
|
||||
|
||||
# 默认自动运行的预置(可自定义顺序)
|
||||
|
||||
AUTO_RUN_PRESETS = ["offline_realdb"]
|
||||
# 默认自动运行的预置(可根据需要修改顺序/条目)
|
||||
AUTO_RUN_PRESETS = ["fetch_only"]
|
||||
|
||||
PRESETS = {
|
||||
"online_orders": {
|
||||
"fetch_only": {
|
||||
"suite": ["online"],
|
||||
"mode": "ONLINE",
|
||||
"flow": "FETCH_ONLY",
|
||||
"json_fetch_root": "tmp/json_fetch",
|
||||
"keyword": "ORDERS",
|
||||
"pytest_args": "-vv",
|
||||
"preset_meta": "在线模式,仅跑订单任务并输出详细日志",
|
||||
"preset_meta": "仅在线抓取阶段,输出到本地目录",
|
||||
},
|
||||
|
||||
"dbrun": {
|
||||
"suite": ["integration"],
|
||||
# "mode": "OFFLINE",
|
||||
# "keyword": "ORDERS",
|
||||
# "pytest_args": "-vv",
|
||||
"preset_meta": "在线模式,仅跑订单任务并输出详细日志",
|
||||
},
|
||||
|
||||
"offline_realdb": {
|
||||
"suite": ["offline"],
|
||||
"mode": "OFFLINE",
|
||||
"db_dsn": "postgresql://local-Python:Neo-local-1991125@100.64.0.4:5432/LLZQ-test",
|
||||
"json_archive": "tests/testdata_json",
|
||||
"ingest_local": {
|
||||
"suite": ["online"],
|
||||
"flow": "INGEST_ONLY",
|
||||
"json_source": "tests/source-data-doc",
|
||||
"keyword": "ORDERS",
|
||||
"preset_meta": "离线模式 + 真实测试库,用预置 JSON 回放并写入测试库",
|
||||
"preset_meta": "从指定 JSON 目录做本地清洗入库",
|
||||
},
|
||||
"full_pipeline": {
|
||||
"suite": ["online"],
|
||||
"flow": "FULL",
|
||||
"json_fetch_root": "tmp/json_fetch",
|
||||
"keyword": "ORDERS",
|
||||
"preset_meta": "先抓取再清洗入库的全流程",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def print_parameter_help() -> None:
|
||||
print("=== 参数键说明 ===")
|
||||
print("suite : 预置套件列表,如 ['online','offline']")
|
||||
print("suite : 预置套件列表,如 ['online','integration']")
|
||||
print("tests : 自定义 pytest 路径列表")
|
||||
print("mode : TEST_MODE(ONLINE/ OFFLINE)")
|
||||
print("db_dsn : TEST_DB_DSN,连接真实 PostgreSQL")
|
||||
print("json_archive : TEST_JSON_ARCHIVE_DIR,离线模式输入目录")
|
||||
print("json_temp : TEST_JSON_TEMP_DIR,离线模式临时目录")
|
||||
print("flow : PIPELINE_FLOW(FETCH_ONLY / INGEST_ONLY / FULL)")
|
||||
print("json_source : JSON_SOURCE_DIR,本地清洗入库使用的 JSON 目录")
|
||||
print("json_fetch_root : JSON_FETCH_ROOT,在线抓取输出根目录")
|
||||
print("keyword : pytest -k 过滤关键字")
|
||||
print("pytest_args : 额外 pytest 参数(字符串)")
|
||||
print("env : 附加环境变量,例如 ['KEY=VALUE']")
|
||||
@@ -120,7 +71,7 @@ def print_presets() -> None:
|
||||
|
||||
def resolve_targets(requested: List[str] | None) -> List[str]:
|
||||
if not PRESETS:
|
||||
raise SystemExit("Pre-sets 为空,请先在 PRESETS 中定义测试组合。")
|
||||
raise SystemExit("预置为空,请先在 PRESETS 中定义测试组合。")
|
||||
|
||||
def valid(names: List[str]) -> List[str]:
|
||||
return [name for name in names if name in PRESETS]
|
||||
@@ -137,7 +88,6 @@ def resolve_targets(requested: List[str] | None) -> List[str]:
|
||||
if auto:
|
||||
return auto
|
||||
|
||||
# 兜底:全部预置
|
||||
return list(PRESETS.keys())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user