Load the test schema once and truncate data between files.
Deploy Development / deploy (push) Successful in 56s
Test Suite / pytest-backend (push) Successful in 2m43s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 15s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-07 15:07:33 +02:00
1 parent 3c0213ae74
commit 79e4fd0d4b
8 files changed
+78 -25

No files matched your search

+20 -12
View File
@@ -1,9 +1,9 @@
"""pytest runner for the existing test_*.py scripts.
Each file stays one case (`main()`) until it is split into native pytest
functions. Integration files reset `kansho_test` only; `kansho_dev` is never
the test target. Provider keys and fake flags are restored per file so the
shared pytest process matches the old one-script-per-process isolation.
functions. Schema is loaded once per session; each integration file only
truncates data so kansho_dev is never the target and CI does not reload
schema.sql twenty times.
"""
from __future__ import annotations
@@ -21,6 +21,7 @@ from tests.harness import ( # noqa: E402
apply_module_env,
is_postgres_test_database,
prepare_test_env,
reset_postgres_data,
reset_postgres_schema,
)
@@ -64,6 +65,20 @@ class KanshoScriptModule(pytest.Module):
yield pytest.Function.from_parent(self, name="test_main", callobj=main)
@pytest.fixture(scope="session")
def _session_postgres():
if not is_postgres_test_database():
pytest.skip(
"integration requires KANSHO_DB_BACKEND=postgres and DB_NAME ending _test "
"(Gitea: kansho_test on the Dev Postgres, never kansho_dev)"
)
reset_postgres_schema()
from db import init_db
init_db()
yield
@pytest.fixture(scope="module", autouse=True)
def _module_backend(request: pytest.FixtureRequest):
source = Path(str(request.path))
@@ -74,15 +89,8 @@ def _module_backend(request: pytest.FixtureRequest):
if stem in UNIT_MODULES:
yield
return
if not is_postgres_test_database():
pytest.skip(
"integration requires KANSHO_DB_BACKEND=postgres and DB_NAME ending _test "
"(Gitea: kansho_test on the Dev Postgres, never kansho_dev)"
)
reset_postgres_schema()
from db import init_db
init_db()
request.getfixturevalue("_session_postgres")
reset_postgres_data()
yield
finally:
os.environ.clear()