Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock with submodules for ReadTheDocs

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?

like image 273
jkibele Avatar asked Sep 15 '15 06:09

jkibele


1 Answers

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.

like image 81
matz-e Avatar answered Nov 15 '22 20:11

matz-e