Bugfix: `Mock` persisted beyond intended test case
What changed, and why it matters
This is a test-only cleanup. A developer fixed a unit test so that a fake version of `os.walk` is only active inside the test that needs it, instead of accidentally staying in place for later tests. It does not change any production code or affect real users.
No security action needed. Treat as a normal code-quality/test-hygiene improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit replaces a global os.walk = Mock(...) assignment in tests/test_settings_definition.py with a scoped with patch('os.walk', ...) context manager. This prevents the mock from leaking into subsequent test cases. The change is confined to the test suite and has no effect on the SeedSigner application runtime.
Changed components
tests/test_settings_definition.pyInspect captured patch +5 / −6
diff --git a/tests/test_settings_definition.py b/tests/test_settings_definition.py
index f95a6c8..794bdba 100644
--- a/tests/test_settings_definition.py
+++ b/tests/test_settings_definition.py
@@ -1,5 +1,5 @@
import os
-from unittest.mock import Mock
+from unittest.mock import patch
from base import BaseTest
from seedsigner.models.settings_definition import SettingsConstants
@@ -31,8 +31,7 @@ class TestSettingsDefinition(BaseTest):
# We're going to mock the `root` results to include the absent language code's .mo file
mocked_results = [(os.path.join(root, "en", "LC_MESSAGES"), [], ["messages.po", "messages.mo"])]
mocked_results.append((os.path.join(root, absent_language_code, "LC_MESSAGES"), [], ["messages.po", "messages.mo"]))
- os.walk = Mock(return_value=mocked_results)
-
- # Recheck w/our mocked dir listing:
- detected_languages = [lang_tuple[0] for lang_tuple in SettingsConstants.get_detected_languages()]
- assert absent_language_code in detected_languages
+ with patch("os.walk", return_value=mocked_results):
+ # Recheck w/our mocked dir listing:
+ detected_languages = [lang_tuple[0] for lang_tuple in SettingsConstants.get_detected_languages()]
+ assert absent_language_code in detected_languages
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.