Bugfix: `Mock` persisted beyond intended test case
What changed, and why it matters
This is a test-only cleanup. A unit test was replacing the `os.walk` function with a fake version and not restoring it afterward, which could cause unrelated later tests to see the fake directory listing. The fix uses Python's `patch` helper that automatically undoes the change after the test. There is no effect on the actual SeedSigner application or its users.
No action needed. This is a benign test-quality fix. If reviewing, confirm the `with patch(...)` context manager is correctly indented and the test still passes.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit changes tests/test_settings_definition.py to replace a manual os.walk = Mock(...) assignment with with patch('os.walk', return_value=mocked_results):. The manual assignment leaked the mock into the global os.walk for any tests run after this one, while patch scopes the mock to the with block and restores the real function afterward. This is purely a test-hygiene fix; no production code is modified.
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.