问题
I'm trying to document a Python project with ReadTheDocs. Initially, the build process would die when it got to:
from osgeo import gdal, osr
I've read the rtd faq and used mock for the osgeo module that was giving me trouble. Now the build process makes it past that import but chokes on:
from osgeo.gdalconst import *
With this rather unhelpful error:
RuntimeError: sys.path must be a list of directory names
I'm completely new to using mock but I think the problem is that osgeo
is a mock module and therefore does not have the submodule gdalconst
. How do I get around that? Is there a way to mock the submodule too?
回答1:
A bit late… but I ran across this looking for a solution (using nested modules with mock
). I've mocked module and submodules like this:
MOCK_MODULES = ['dbs', 'dbs.apis', 'dbs.apis.dbsClient']
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
where the order mattered. Hope this helps anyone else looking to solve this.
来源:https://stackoverflow.com/questions/32579380/mock-with-submodules-for-readthedocs