Isolate tests from ambient .env; fix begin_nested mock warning #26
No reviewers
Labels
No labels
area:ai
area:ci-cd
area:notifications
area:observability
area:public-pages
backlog
bug
duplicate
enhancement
help wanted
invalid
question
type:decision
type:feature
type:infra
type:maintenance
type:security
v1.0.1
v1.1.0
v1.2.0
v1.3.0
v2.0.0
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rbrooks/WeatherBot!26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "chore/test-env-isolation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Resolves issue #5. Investigation found no pytest-asyncio deprecation warnings on the pinned stack (pytest 9 / pytest-asyncio 1.x / Python 3.12) — the security-plan note was prospective for Python 3.14. The actual problem surfaced when running the suite on a host with a real
.env:Settingsloads.envfrom the working directory (app/config.py). On the dev server, that.env(non-httpsAPP_BASE_URL,PUBLIC_ALERT_PAGES_ENABLED=true) leaked intoSettings(), causing:test_config.pyfailures (production validators tripped on the devAPP_BASE_URL), andRuntimeWarning: coroutine ... never awaited— public alert pages became enabled, so_ensure_public_alert_pageenteredasync with db.begin_nested():against a mock that didn't modelbegin_nested.On clean CI (no
.env) the suite was green, which hid both.Changes
tests/conftest.py— disable dotenv loading beforeapp.mainis imported, soSettingsuses defaults regardless of host (matches CI). Makes the suite environment-independent.tests/test_alert_processor.py— mockdb.begin_nested()as a sync call returning an async context manager.Validation
Run on the dev server with its real
.envcopied into a throwaway worktree (reproduces the contamination):Clean CI was already green; this makes a
.env-bearing host green too.Closes #5