pytest rewrites config/vigilar.toml in place — test isolation bug #3
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Severity: bug
Files:
vigilar/config.py:420,vigilar/web/blueprints/system.py:24, some web test (unidentified)Running the full
pytestsuite from a clean checkout modifies the committedconfig/vigilar.toml: comments are stripped,[[cameras]]/[[sensors]]/[[rules]]blocks are dropped, and default field values are materialized. Git shows it asM config/vigilar.tomlafterpytestexits.Root cause: Both
load_config()(vigilar/config.py:420) and_get_config_path()(vigilar/web/blueprints/system.py:24) default to the relative path"config/vigilar.toml"when theVIGILAR_CONFIGenv var is unset. Some test exercises a web endpoint that calls_save_and_reload(), which callssave_config()against whatever path_get_config_path()returns. Because the tests don't setVIGILAR_CONFIG, the real on-disk config is rewritten via a Pydanticmodel_dump()round-trip.Fix options:
conftest.py: setVIGILAR_CONFIGto atmp_pathfixture for all tests, or autouse a fixture that does so._get_config_pathor injectVIGILAR_CONFIG._save_and_reloadto refuse to write when the target path resolves to a tracked file under the repo.Reproduce:
git clean -f && git checkout config/vigilar.toml && pytest -q && git status --short—config/vigilar.tomlwill be listed as modified.Discovered while working on unrelated fixes in branch
fix/audit-followups.