Skip to content

Commit 8ba5553

Browse files
committed
Add another test in implicit files that loads the resource from a submodule.
1 parent 34ed4f7 commit 8ba5553

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

importlib_resources/tests/test_files.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,33 @@ class ModuleFilesZipTests(DirectSpec, util.ZipSetup, ModulesFiles, unittest.Test
9999

100100

101101
class ImplicitContextFiles:
102+
set_val = textwrap.dedent(
103+
"""
104+
import importlib_resources as res
105+
val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
106+
"""
107+
)
102108
spec = {
103109
'somepkg': {
104-
'__init__.py': textwrap.dedent(
105-
"""
106-
import importlib_resources as res
107-
val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
108-
"""
109-
),
110+
'__init__.py': set_val,
111+
'submod.py': set_val,
110112
'res.txt': 'resources are the best',
111113
},
112114
}
113115

114-
def test_implicit_files(self):
116+
def test_implicit_files_package(self):
115117
"""
116118
Without any parameter, files() will infer the location as the caller.
117119
"""
118120
assert importlib.import_module('somepkg').val == 'resources are the best'
119121

122+
@pytest.mark.xfail(reason="python/cpython#121735")
123+
def test_implicit_files_submodule(self):
124+
"""
125+
Without any parameter, files() will infer the location as the caller.
126+
"""
127+
assert importlib.import_module('somepkg.submod').val == 'resources are the best'
128+
120129

121130
class ImplicitContextFilesDiskTests(
122131
DirectSpec, util.DiskSetup, ImplicitContextFiles, unittest.TestCase

0 commit comments

Comments
 (0)