Skip to content

Commit 47d73b1

Browse files
committed
Add test capturing failure when resolving the MultiplexedPath for a namespace package with non-path elements in the path.
Ref #311
1 parent 4875bc5 commit 47d73b1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

importlib_resources/tests/test_files.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import importlib
99
import contextlib
1010

11+
import pytest
12+
1113
import importlib_resources as resources
1214
from ..abc import Traversable
1315
from . import util
@@ -60,6 +62,27 @@ class OpenZipTests(FilesTests, util.ZipSetup, unittest.TestCase):
6062
class OpenNamespaceTests(FilesTests, util.DiskSetup, unittest.TestCase):
6163
MODULE = 'namespacedata01'
6264

65+
@pytest.mark.xfail(reason="#311")
66+
def test_non_paths_in_dunder_path(self):
67+
"""
68+
Non-path items in a namespace package's ``__path__`` are ignored.
69+
70+
As reported in python/importlib_resources#311, some tools
71+
like Setuptools, when creating editable packages, will inject
72+
non-paths into a namespace package's ``__path__``, a
73+
sentinel like
74+
``__editable__.sample_namespace-1.0.finder.__path_hook__``
75+
to cause the ``PathEntryFinder`` to be called when searching
76+
for packages. In that case, resources should still be loadable.
77+
"""
78+
import namespacedata01
79+
80+
namespacedata01.__path__.append(
81+
'__editable__.sample_namespace-1.0.finder.__path_hook__'
82+
)
83+
84+
resources.files(namespacedata01)
85+
6386

6487
class OpenNamespaceZipTests(FilesTests, util.ZipSetup, unittest.TestCase):
6588
ZIP_MODULE = 'namespacedata01'

0 commit comments

Comments
 (0)