Mock with submodules for ReadTheDocs

吃可爱长大的小学妹 提交于 2019-12-21 09:27:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!