Merge pull request #4980 from blueyed/fixup_namespace_packages
monkeypatch.syspath_prepend: call fixup_namespace_packages
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -593,11 +593,16 @@ class Testdir(object):
|
||||
|
||||
This is undone automatically when this object dies at the end of each
|
||||
test.
|
||||
|
||||
"""
|
||||
from pkg_resources import fixup_namespace_packages
|
||||
|
||||
if path is None:
|
||||
path = self.tmpdir
|
||||
sys.path.insert(0, str(path))
|
||||
|
||||
dirname = str(path)
|
||||
sys.path.insert(0, dirname)
|
||||
fixup_namespace_packages(dirname)
|
||||
|
||||
# a call to syspathinsert() usually means that the caller wants to
|
||||
# import some dynamically created files, thus with python3 we
|
||||
# invalidate its import caches
|
||||
@@ -606,12 +611,10 @@ class Testdir(object):
|
||||
def _possibly_invalidate_import_caches(self):
|
||||
# invalidate caches if we can (py33 and above)
|
||||
try:
|
||||
import importlib
|
||||
from importlib import invalidate_caches
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if hasattr(importlib, "invalidate_caches"):
|
||||
importlib.invalidate_caches()
|
||||
return
|
||||
invalidate_caches()
|
||||
|
||||
def mkdir(self, name):
|
||||
"""Create a new (sub)directory."""
|
||||
|
||||
Reference in New Issue
Block a user