refactor: 预留并行修复所需的共享接口
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""在导入 app 之前把数据和下载目录指到临时目录。"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
_TEMP = Path(__file__).resolve().parents[2] / "Temp"
|
||||
_TEMP.mkdir(parents=True, exist_ok=True)
|
||||
_ROOT = Path(tempfile.mkdtemp(prefix="pytest-", dir=_TEMP))
|
||||
os.environ["NQI_DATA_DIR"] = str(_ROOT / "data")
|
||||
os.environ["NQI_DOWNLOAD_DIR"] = str(_ROOT / "downloads")
|
||||
|
||||
if "app" in sys.modules or "app.shared.paths" in sys.modules:
|
||||
raise RuntimeError("测试必须在导入 app 之前设置 NQI_DATA_DIR 和 NQI_DOWNLOAD_DIR")
|
||||
|
||||
|
||||
def pytest_configure() -> None:
|
||||
from app.shared.paths import DATA_ROOT, DOWNLOAD_ROOT
|
||||
|
||||
if DATA_ROOT != Path(os.environ["NQI_DATA_DIR"]):
|
||||
raise RuntimeError("DATA_ROOT 没有使用 NQI_DATA_DIR")
|
||||
if DOWNLOAD_ROOT != Path(os.environ["NQI_DOWNLOAD_DIR"]):
|
||||
raise RuntimeError("DOWNLOAD_ROOT 没有使用 NQI_DOWNLOAD_DIR")
|
||||
if DOWNLOAD_ROOT.exists():
|
||||
raise RuntimeError("导入时不应创建下载目录")
|
||||
@@ -487,9 +487,7 @@ def test_only_the_task_limit_runs(tmp_path: Path, monkeypatch):
|
||||
assert manager.place(third) == "run"
|
||||
assert manager.place(first) == "wait"
|
||||
manager.jobs.clear()
|
||||
manager.hydrate()
|
||||
assert first.id in manager.jobs
|
||||
assert manager.jobs[first.id].status == "queued"
|
||||
assert first.id not in manager.jobs
|
||||
assert third.id not in manager.jobs
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user