test: isolate VIGILAR_CONFIG via autouse session fixture (fixes #3) #5
Reference in New Issue
Block a user
Delete Branch "fix/issue-3-test-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?
Fixes #3.
Problem
Running the full
pytestsuite from a clean checkout rewrites the committedconfig/vigilar.tomlvia a Pydanticmodel_dump()round-trip (comments stripped, cameras/sensors/rules dropped, default fields materialized).Root cause
vigilar/web/blueprints/system.py:24—_get_config_path()defaults to the relative path"config/vigilar.toml"whenVIGILAR_CONFIGis unset.test_reset_pin_correct_passphraseintests/unit/test_system_pin.pyexercisesPOST /system/api/reset-pin, whose handler calls_save_and_reload()→save_config(new_cfg, _get_config_path()). With no env var, the real on-disk config is rewritten.Reproduction:
Fix
Add an autouse session-scoped fixture in
tests/conftest.pythat pointsVIGILAR_CONFIGat a path inside pytest's session tmp dir. Every test inherits the safe default; no test can touch the real file. Previous env var value is restored on teardown.Verification
pytest -q tests/unit/test_system_pin.py::test_reset_pin_correct_passphrase— passes,config/vigilar.tomlunchanged.pytest -q— 360/360 passing,config/vigilar.tomlunchanged.