test(backend): stop test_action_items_timezone from poisoning sys.modules (#8661)#8680
Merged
kodjima33 merged 1 commit intoJul 1, 2026
Conversation
…ules (BasedHardware#8661) The module-level stub setup replaced real packages (utils, utils.retrieval, utils.conversations, database, langchain_core) with empty types.ModuleType stubs and never restored them. During a bulk `pytest tests/unit/` run, every test file collected alphabetically after this one then failed to import from those packages (issue BasedHardware#8661: 39 collection errors, 38 of which pass when run individually). Snapshot sys.modules before stubbing and restore it right after the module under test is imported. The tool reference is already bound to the stubbed dependencies, and the tests patch action_item_tools.action_items_db directly, so behaviour is unchanged. Verified: the file's own tests still pass (11 passed), and the issue's repro `pytest tests/unit/test_action_items_timezone.py tests/unit/test_apps_create_app_json.py` now passes (26 passed, previously a collection ERROR).
Git-on-my-level
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for isolating this — the fix is small and targeted, and the approach makes sense for the current test structure.
I reviewed the diff and ran the focused regression locally in a clean worktree with secrets stripped:
python -m pytest tests/unit/test_action_items_timezone.py tests/unit/test_apps_create_app_json.py -q
Result: 26 passed.
I’m leaving this as a positive signal rather than a formal approval because this is explicitly one slice of the broader #8661 sys.modules/test-isolation cleanup, so a human maintainer should decide whether to merge this partial fix as-is or wait for the remaining related cleanup. No blocking code concerns from my review.
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.
What
Fixes the
test_action_items_timezone.pypart of #8661.This file installed its stubs by writing to
sys.modulesat module scope and never restored them. The_stub_package()helper replaced real packages (utils,utils.retrieval,utils.retrieval.tools,utils.conversations,database,langchain_core) with emptytypes.ModuleTypestubs. During a bulkpytest tests/unit/run, pytest collects every file, so this file's module-level code ran and permanently replaced those packages, and every test file collected alphabetically after it then failed to import from them.Fix
Snapshot
sys.modulesbefore the stubbing begins, and restore it right after the module under test (action_item_tools) is imported:The loaded module keeps its references to the stubbed dependencies (Python binds them at import time), and the tests patch
action_item_tools.action_items_dbdirectly rather than by string path, so the restore does not change behaviour.Verification
This addresses one of the three module-level-stub files in #8661. The other two (
test_action_item_date_validation.py,test_tools_router.py) and the missingfake-firestoredependency are out of scope here.