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 doctest
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import importlib.util
|
import importlib
|
||||||
|
|
||||||
import preserves
|
import preserves
|
||||||
|
|
||||||
def load_tests(loader, tests, ignore):
|
def load_tests(loader, tests, ignore):
|
||||||
def m(spec):
|
mods = []
|
||||||
mod = importlib.util.module_from_spec(spec)
|
mods.append(preserves)
|
||||||
mod.__loader__.exec_module(mod)
|
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))
|
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
|
return tests
|
||||||
|
|
Loading…
Reference in New Issue