summaryrefslogtreecommitdiff
path: root/testing/test_monkeypatch.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-03-22 14:36:11 +0100
committerDaniel Hahler <git@thequod.de>2019-03-22 15:29:08 +0100
commit475119988ce4960bc7356a82d8ea2518d2c6089d (patch)
tree951ce7061fc5624abcaacd843227cb1d8d3082f3 /testing/test_monkeypatch.py
parent15d608867dfa0fea5de4d9385dd2da8191ec0b8c (diff)
downloadpytest-475119988ce4960bc7356a82d8ea2518d2c6089d.tar.gz
monkeypatch.syspath_prepend: call fixup_namespace_packages
Without the patch the test fails as follows: # Prepending should call fixup_namespace_packages. monkeypatch.syspath_prepend("world") > import ns_pkg.world E ModuleNotFoundError: No module named 'ns_pkg.world'
Diffstat (limited to 'testing/test_monkeypatch.py')
-rw-r--r--testing/test_monkeypatch.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py
index 0a953d3f1..d43fb6bab 100644
--- a/testing/test_monkeypatch.py
+++ b/testing/test_monkeypatch.py
@@ -437,3 +437,28 @@ def test_context():
m.setattr(functools, "partial", 3)
assert not inspect.isclass(functools.partial)
assert inspect.isclass(functools.partial)
+
+
+def test_syspath_prepend_with_namespace_packages(testdir, monkeypatch):
+ for dirname in "hello", "world":
+ d = testdir.mkdir(dirname)
+ ns = d.mkdir("ns_pkg")
+ ns.join("__init__.py").write(
+ "__import__('pkg_resources').declare_namespace(__name__)"
+ )
+ lib = ns.mkdir(dirname)
+ lib.join("__init__.py").write("def check(): return %r" % dirname)
+
+ monkeypatch.syspath_prepend("hello")
+ import ns_pkg.hello
+
+ assert ns_pkg.hello.check() == "hello"
+
+ with pytest.raises(ImportError):
+ import ns_pkg.world
+
+ # Prepending should call fixup_namespace_packages.
+ monkeypatch.syspath_prepend("world")
+ import ns_pkg.world
+
+ assert ns_pkg.world.check() == "world"