Isolate tests from global config (#470)#647
Open
arpitjain099 wants to merge 1 commit into
Open
Conversation
ConfigManager is a process-wide singleton that, with the default config_dir=None, reads the developer's real user config such as ~/.config/surfactant/config.toml. An invalid value there (for example core.output_format = "") makes otherwise-correct tests fail, since some command modules evaluate config-backed defaults at import time. Add tests/conftest.py that redirects the config and data lookups to empty temporary directories, both at import time (before command modules are imported) and per test via an autouse fixture, and clears the singleton cache so each test starts from a clean, isolated configuration. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
Summary
If merged this pull request will make the test suite pass regardless of the developer's global Surfactant settings, fixing #470.
Proposed changes
ConfigManager is a process-wide singleton and, with the default config_dir=None, it reads the real user config (for example ~/.config/surfactant/config.toml). A few command modules evaluate config-backed defaults at import time, so an invalid global value like core.output_format = "" leaks into unrelated tests and fails them. I could reproduce it by writing that setting and running pytest: eight tests in test_generate.py, test_generate_symlinks.py, and test_tui.py errored with 'No "write_sbom" plugin for format "" found', and they all pass again with this change.
This adds a tests/conftest.py that points the config and data lookups at empty temporary directories, both at import time (before the command modules are imported) and per test through an autouse fixture, and clears the singleton cache so each test starts from a clean, isolated config. Existing ConfigManager tests still pass since they use explicit app names and config dirs. Thanks for taking a look.