Fix doctest module loading to avoid double-creation of modules
This commit is contained in:
parent
031575ad82
commit
99258be1ef
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue