From 99258be1ef2f6ca524ebd2d2a357e527ea1c9c30 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 16 Mar 2023 20:12:17 +0100 Subject: [PATCH] Fix doctest module loading to avoid double-creation of modules --- implementations/python/tests/test_doctests.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/implementations/python/tests/test_doctests.py b/implementations/python/tests/test_doctests.py index a29fd4c..06d249c 100644 --- a/implementations/python/tests/test_doctests.py +++ b/implementations/python/tests/test_doctests.py @@ -1,17 +1,17 @@ import doctest import pkgutil -import importlib.util +import importlib import preserves def load_tests(loader, tests, ignore): - def m(spec): - mod = importlib.util.module_from_spec(spec) - mod.__loader__.exec_module(mod) + mods = [] + mods.append(preserves) + for mi in pkgutil.iter_modules(preserves.__path__, preserves.__name__ + '.'): + mod = importlib.import_module(mi.name) + mods.append(mod) + + for mod in mods: tests.addTests(doctest.DocTestSuite(mod)) - spec = preserves.__spec__ - m(spec) - for mi in pkgutil.walk_packages(spec.submodule_search_locations, spec.name + '.'): - subspec = mi.module_finder.find_spec(mi.name) - m(subspec) + return tests