monkeypatch.syspath_prepend: call fixup_namespace_packages

Without the patch the test fails as follows:

            # Prepending should call fixup_namespace_packages.
            monkeypatch.syspath_prepend("world")
    >       import ns_pkg.world
    E       ModuleNotFoundError: No module named 'ns_pkg.world'
This commit is contained in:
Daniel Hahler
2019-03-22 14:36:11 +01:00
parent 15d608867d
commit 475119988c
3 changed files with 31 additions and 0 deletions

View File

@@ -262,10 +262,15 @@ class MonkeyPatch(object):
def syspath_prepend(self, path):
""" Prepend ``path`` to ``sys.path`` list of import locations. """
from pkg_resources import fixup_namespace_packages
if self._savesyspath is None:
self._savesyspath = sys.path[:]
sys.path.insert(0, str(path))
# https://github.com/pypa/setuptools/blob/d8b901bc/docs/pkg_resources.txt#L162-L171
fixup_namespace_packages(str(path))
def chdir(self, path):
""" Change the current working directory to the specified path.
Path can be a string or a py.path.local object.