From e6505790c26c71b26be4bc71c57a91bb2845daab Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 24 Nov 2026 20:52:37 -0500 Subject: [PATCH] Let the speech tests load speech.py inside a package again speech.py now imports its translations relatively, so loading it on its own failed with ModuleNotFoundError and every speech test errored. The tests now give it a package of its own, as the menu tests do. Co-Authored-By: Claude Opus 5.5 --- tests/test_speech.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_speech.py b/tests/test_speech.py index cc02f26..81aba22 100644 --- a/tests/test_speech.py +++ b/tests/test_speech.py @@ -12,10 +12,14 @@ import pygame def load_speech(): """Load speech code without initializing the library or a speech provider.""" - spec = importlib.util.spec_from_file_location( - "_speech_test_library.speech", Path(__file__).resolve().parents[1] / "speech.py") + packageName = "_speech_test_library" + # A package of its own, so speech's relative imports, such as its translations, resolve without the library. + package = ModuleType(packageName) + package.__path__ = [str(Path(__file__).resolve().parents[1])] + spec = importlib.util.spec_from_file_location(f"{packageName}.speech", Path(package.__path__[0]) / "speech.py") module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) + with patch.dict(sys.modules, {packageName: package}): + spec.loader.exec_module(module) return module