WebSearch: fix bare imports in test_filetable for dotted-path loading#833
Conversation
|
Added your fix of test_filetable.py to branch 6.1 fixes for unittest - #832 I think this PR should just be a single file change, I suspect you need to rebase to gramps60 to separate out PR 820 and this change. Please review PR 832 for the changes for 6.1 . I am not too familiar with unittest and would appreciate the review. |
`WebSearch/tests/test_filetable.py` imports `models`, `constants` and
`db_file_table` without a package prefix. Those resolve only when
`WebSearch/` itself is on sys.path — i.e. when the test is loaded via
`unittest discover` from inside `tests/`. Under the dotted-path form
that addons-source's own ci.yml uses (`python3 -m unittest
WebSearch.tests.test_filetable` from the addons-source root), the
imports look for a top-level `models` module and the test fails to
load:
ImportError: Failed to import test module: test_filetable
ModuleNotFoundError: No module named 'models'
Add the same `sys.path.insert(0, …parent dir…)` prologue that
TMGimporter and Form already use for the same pattern, so the test
loads under either form. No behavioural change beyond the imports.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ef9a900 to
1c675ba
Compare
|
Thanks @GaryGriffin — rebased onto Happy to review #832 — I'll leave specific comments there. One thing to flag in advance: in #832's I'll detail it as a review on #832 with a concrete suggested fix. |
Summary
WebSearch/tests/test_filetable.py(added in WebSearch 1.10.7, commit e3750a0) importsmodels,constantsanddb_file_tablewithout a package prefix:Those resolve only when
WebSearch/itself is onsys.path— i.e. when the test is loaded viaunittest discoverfrom insidetests/. Under the dotted-path invocation that fork CI'sunit-test-linuxjob uses (python3 -m unittest WebSearch.tests.test_filetablefrom the addons-source root, withPYTHONPATH=.), the imports look for a top-levelmodelsmodule and the test module fails to load:This is the same package-shadowing class of bug as 0012691 — the dotted-path loader is what surfaces it;
discoverfromtests/hides it.Fix
Add the
sys.path.insert(0, …parent dir…)prologue thatTMGimporter/tests/test_libtmg.pyandForm/tests/test_form_validator.pyalready use for sibling-module imports — the established in-tree convention for this exact case. No behavioural change beyond the imports.Verification
cd addons-source && PYTHONPATH=. python3 -m unittest -v WebSearch.tests.test_filetable-> ImportError / ModuleNotFoundError.Ran 28 tests in 0.008s -- OK.Reproduced & verified in a sibling testbed (gramps-testbed) that runs every addon's
tests/test_*.pyvia the dotted-path form, which is how this trap surfaces in the first place.Remarks
This is one of the fixes required for the CI PR I've proposed to run clean on the repos.
🤖 Generated with Claude Code