Skip to content

Commit 5df45f5

Browse files
committed
Use fixup_namespace_packages also with pytester.syspathinsert
1 parent 05d55b8 commit 5df45f5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

changelog/4980.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
``monkeypatch.syspath_prepend`` calls ``pkg_resources.fixup_namespace_packages`` to handle namespace packages better.
1+
Namespace packages are handled better with ``monkeypatch.syspath_prepend`` and ``testdir.syspathinsert`` (via ``pkg_resources.fixup_namespace_packages``).

src/_pytest/pytester.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,16 @@ def syspathinsert(self, path=None):
593593
594594
This is undone automatically when this object dies at the end of each
595595
test.
596-
597596
"""
597+
from pkg_resources import fixup_namespace_packages
598+
598599
if path is None:
599600
path = self.tmpdir
600-
sys.path.insert(0, str(path))
601+
602+
dirname = str(path)
603+
sys.path.insert(0, dirname)
604+
fixup_namespace_packages(dirname)
605+
601606
# a call to syspathinsert() usually means that the caller wants to
602607
# import some dynamically created files, thus with python3 we
603608
# invalidate its import caches

0 commit comments

Comments
 (0)