test: isolate settings-save tests from the shared on-device config - #3215
Merged
vpetersson merged 2 commits intoJul 27, 2026
Merged
Conversation
The settings-save tests in test_template_views.py posted through the settings_save view (or called settings.save() directly) against the real ~/.anthias/anthias.conf, and did not restore it. That leaks values onto the shared on-device config and breaks later tests that read defaults back from it. Concretely, when the non-integration and integration suites run against the same /data volume, test_settings_save_invalid_default_streaming_duration persisted default_duration=0 (clamp_duration coerces the non-numeric input to 0), after which the integration test test_add_asset_via_url failed with `assert 10 == 0` — it expects a new asset to inherit the default duration. CI does not hit this because it isolates the two suites into separate jobs with fresh containers. Add a reusable _isolated_settings_conf fixture that redirects the settings singleton's conf_file to a per-test tmp path and reloads on teardown (generalising the redirect already used by _reset_review_cta), and apply it to the settings-save tests. This also lets the two timezone tests drop their manual save/restore bookkeeping. While here, fix test_settings_save_invalid_default_streaming_duration: its docstring claimed to exercise the handler's except branch, but clamp_duration swallows the ValueError and returns 0, so that branch is never reached. Point the invalid value at the field the test is named for and assert the clamped result is actually persisted. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01HJ3ucEkn62cbgPoisAZ5LQ
There was a problem hiding this comment.
Pull request overview
This PR updates the Django template-view test suite to prevent settings_save tests from mutating the shared on-device ~/.anthias/anthias.conf, which can leak state across test suites when they run against the same /data volume.
Changes:
- Added a reusable pytest fixture to redirect the
anthias_server.settings.settingssingleton’sconf_fileto a per-test temp path and restore it afterwards. - Updated
settings_save-related tests to use the new isolation fixture and removed manual save/restore bookkeeping in timezone tests. - Corrected the invalid-duration test to target
default_streaming_durationand assert the clamped persisted result.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3215 +/- ##
=========================================
Coverage ? 89.46%
=========================================
Files ? 76
Lines ? 8340
Branches ? 890
=========================================
Hits ? 7461
Misses ? 665
Partials ? 214 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Move the conf_file reassignment and initial save() inside the try so a failure there can't leave the settings singleton pointed at the temp path for the rest of the session; the finally now always restores it. Addresses PR review feedback. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01HJ3ucEkn62cbgPoisAZ5LQ
|
vpetersson
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
The
settings_savetests intests/test_template_views.pywrite to the real~/.anthias/anthias.conf(via thesettings_saveview or a directsettings.save()) and don't restore it. That leaks their posted values onto the shared on-device config, breaking later tests that read defaults back from it.It surfaces when the non-integration and integration suites run against the same
/datavolume (the sequence documented inCLAUDE.md):test_settings_save_invalid_default_streaming_durationposts a non-numeric duration;clamp_durationcoerces it to0and the handler persistsdefault_duration = 0.test_add_asset_via_urlthen fails withassert 10 == 0— it expects a newly added asset to inherit the default duration, which is now0on disk.CI is green today because it isolates the two suites into separate jobs with fresh containers, so the integration job never sees the polluted config. This only bites a developer running both suites locally against one stack.
Fix
_isolated_settings_conffixture that redirects the settings singleton'sconf_fileto a per-test tmp path and reloads on teardown — generalising the redirect already used by_reset_review_cta— and apply it to the settings-save tests. The two timezone tests can then drop their manual save/restore bookkeeping.test_settings_save_invalid_default_streaming_duration: its docstring claimed to exercise the handler'sexceptbranch, butclamp_durationswallows theValueErrorand returns0, so that branch is never reached. Point the invalid value at the field the test is named for and assert the clamped result is actually persisted.No production code changes.
Verification
default_durationstays10afterwards (was flipped to0before this change).ruff==0.15.21(the pinned version): clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01HJ3ucEkn62cbgPoisAZ5LQ