gabriel / musehub public
test_no_db_sessions.py python
38 lines 1.7 KB
Raw
sha256:a977b39d08e15683210a33608e25712fe3ed9c8f05f0388fb69ef38acf835426 feat(release): hermetic release gates in a provisioned, pin… Opus 5.5 minor ⚠ breaking 12 days ago
1 """A session of DB-free suites must not need (or touch) Postgres (musehub#114 Phase 6D, D6).
2
3 Run in a subprocess with an unreachable database URL: if the autouse schema fixture still connected,
4 the inner pytest would error. The release gates rely on this to be independent of the operator's machine.
5 """
6
7 from __future__ import annotations
8
9 import os
10 import pathlib
11 import subprocess
12 import sys
13
14 ROOT = pathlib.Path(__file__).resolve().parents[1]
15 NO_DB_URL = "postgresql+asyncpg://gate-has-no-database.invalid:1/none"
16
17
18 def run(*args: str) -> subprocess.CompletedProcess[str]:
19 env = {**os.environ, "TEST_DATABASE_URL": NO_DB_URL}
20 return subprocess.run(
21 [sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider", *args], cwd=ROOT, env=env, capture_output=True, text=True, timeout=300
22 )
23
24
25 def test_release_suites_pass_with_no_database_reachable() -> None:
26 proc = run("tests/test_release_activation.py", "tests/test_prune_releases.py", "tests/test_release_gate_env.py")
27 assert proc.returncode == 0, proc.stdout[-1500:] + proc.stderr[-500:]
28
29
30 def test_a_db_backed_test_inside_a_release_file_keeps_the_schema_fixture_alive() -> None:
31 proc = run("tests/test_release_selection.py")
32 assert proc.returncode != 0 and "gate-has-no-database" in (proc.stdout + proc.stderr)
33
34
35 def test_a_session_containing_a_database_test_still_requires_the_database() -> None:
36 """The skip is opt-in per test file; it must not silently disable the schema for DB-backed suites."""
37 proc = run("tests/test_deployment.py::TestZeroDowntimeDeploy::test_two_slots_defined", "tests/test_release_selection.py")
38 assert proc.returncode != 0 and "gate-has-no-database" in (proc.stdout + proc.stderr)
File History 1 commit
sha256:a977b39d08e15683210a33608e25712fe3ed9c8f05f0388fb69ef38acf835426 feat(release): hermetic release gates in a provisioned, pin… Opus 5.5 minor ⚠ 12 days ago