fix: 测试库按进程隔离,主题在无法写存储时仍能打开

This commit is contained in:
2026-11-16 11:34:58 +08:00
parent f06258790f
commit 17c0defa72
7 changed files with 27 additions and 22 deletions
+3
View File
@@ -0,0 +1,3 @@
[pytest]
testpaths = tests
pythonpath = .
+1
View File
@@ -1 +1,2 @@
-r requirements.txt
pytest==9.1.1
+4 -8
View File
@@ -9,7 +9,7 @@ sys.path.insert(0, str(_backend))
_root = _backend.parent / "Temp" / "pytest"
_root.mkdir(parents=True, exist_ok=True)
os.environ["EUNIV_SECRET_KEY"] = "test-secret-key-0123456789abcdef"
os.environ["EUNIV_DB_PATH"] = str(_root / "euniv.db")
os.environ["EUNIV_DB_PATH"] = str(_root / f"euniv-{os.getpid()}.db")
os.environ["EUNIV_DISABLE_REFRESH"] = "1"
os.environ["EUNIV_ADMIN_PASSWORD"] = "test-admin-pass"
os.environ["EUNIV_COOKIE_SECURE"] = "0"
@@ -22,15 +22,11 @@ def fresh_database():
from admin.settings import ensure_admin_seed, ensure_key_check, load_admin_identity
from euniv.db import engine, init_db
from euniv.models import Base
import admin.models # noqa: F401
Base.metadata.drop_all(bind=engine)
with engine.begin() as connection:
connection.execute(text("DROP TABLE IF EXISTS accounts"))
connection.execute(text("DROP TABLE IF EXISTS system_config"))
connection.execute(text("DROP TABLE IF EXISTS courses"))
connection.execute(text("DROP TABLE IF EXISTS course_sync"))
connection.execute(text("DROP TABLE IF EXISTS proxy_nodes"))
connection.execute(text("DROP TABLE IF EXISTS proxy_pool_sync"))
connection.execute(text("DROP TABLE IF EXISTS finished_courses"))
connection.execute(text("DROP TABLE IF EXISTS alembic_version"))
init_db()
ensure_admin_seed()