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