Mock with submodules for ReadTheDocs
Question: 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](https://read-the-
docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-
depend-on-c-modules) 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?


Answer: 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.

