generated from john/python-template
This commit is contained in:
@@ -24,6 +24,32 @@ from transcription.services.documents import DocumentService
|
||||
from transcription.services.jobs import JobService
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def isolate_settings_from_local_env_files(tmp_path_factory):
|
||||
"""Point `Settings` at a controlled stub env file instead of a developer one.
|
||||
|
||||
`Settings.model_config` declares `env_file=".env.production"`, resolved against the
|
||||
current working directory, so a repository-root pytest run would otherwise read real
|
||||
deployment values into tests that assert declared defaults.
|
||||
|
||||
The stub mirrors what `.github/workflows/quality-gate.yml` writes in CI: only
|
||||
`OPENROUTER_API_KEY`, which is required and which many tests need `get_settings()` to
|
||||
find. Everything else falls back to declared defaults, so local and CI runs agree. This
|
||||
stays a file rather than a process environment variable because
|
||||
`test_config.py::test_requires_api_key` asserts the missing-key failure via
|
||||
`_env_file=None`. Guarded by `tests/test_config_isolation.py`.
|
||||
"""
|
||||
stub = tmp_path_factory.mktemp("settings-env") / ".env.test"
|
||||
stub.write_text("OPENROUTER_API_KEY=test-placeholder-not-a-real-key\n", encoding="utf-8")
|
||||
|
||||
original = Settings.model_config.get("env_file")
|
||||
Settings.model_config["env_file"] = str(stub)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
Settings.model_config["env_file"] = original
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session():
|
||||
"""Provide a clean synchronous database session for sync tests."""
|
||||
|
||||
Reference in New Issue
Block a user