Merge pull request #8503 from pytest-dev/require_setuptools
monkeypatch.syspath_prepend: Skip fixup_namespace_packages if pkg_resources not imported
This commit is contained in:
commit
9c151a65c8
|
@ -0,0 +1,4 @@
|
||||||
|
:meth:`pytest.MonkeyPatch.syspath_prepend` no longer fails when
|
||||||
|
``setuptools`` is not installed.
|
||||||
|
It now only calls :func:`pkg_resources.fixup_namespace_packages` if
|
||||||
|
``pkg_resources`` was previously imported, because it is not needed otherwise.
|
|
@ -312,13 +312,16 @@ class MonkeyPatch:
|
||||||
|
|
||||||
def syspath_prepend(self, path) -> None:
|
def syspath_prepend(self, path) -> None:
|
||||||
"""Prepend ``path`` to ``sys.path`` list of import locations."""
|
"""Prepend ``path`` to ``sys.path`` list of import locations."""
|
||||||
from pkg_resources import fixup_namespace_packages
|
|
||||||
|
|
||||||
if self._savesyspath is None:
|
if self._savesyspath is None:
|
||||||
self._savesyspath = sys.path[:]
|
self._savesyspath = sys.path[:]
|
||||||
sys.path.insert(0, str(path))
|
sys.path.insert(0, str(path))
|
||||||
|
|
||||||
# https://github.com/pypa/setuptools/blob/d8b901bc/docs/pkg_resources.txt#L162-L171
|
# https://github.com/pypa/setuptools/blob/d8b901bc/docs/pkg_resources.txt#L162-L171
|
||||||
|
# this is only needed when pkg_resources was already loaded by the namespace package
|
||||||
|
if "pkg_resources" in sys.modules:
|
||||||
|
from pkg_resources import fixup_namespace_packages
|
||||||
|
|
||||||
fixup_namespace_packages(str(path))
|
fixup_namespace_packages(str(path))
|
||||||
|
|
||||||
# A call to syspathinsert() usually means that the caller wants to
|
# A call to syspathinsert() usually means that the caller wants to
|
||||||
|
|
Loading…
Reference in New Issue