From 5df45f5b278ce3ed5e8dbfba67d317416dcc6c84 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 22 Mar 2019 16:26:55 +0100 Subject: [PATCH] Use fixup_namespace_packages also with pytester.syspathinsert --- changelog/4980.feature.rst | 2 +- src/_pytest/pytester.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/changelog/4980.feature.rst b/changelog/4980.feature.rst index 1c42547c1..40f1de9c1 100644 --- a/changelog/4980.feature.rst +++ b/changelog/4980.feature.rst @@ -1 +1 @@ -``monkeypatch.syspath_prepend`` calls ``pkg_resources.fixup_namespace_packages`` to handle namespace packages better. +Namespace packages are handled better with ``monkeypatch.syspath_prepend`` and ``testdir.syspathinsert`` (via ``pkg_resources.fixup_namespace_packages``). diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index ffcd2982a..bc1405176 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -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