[py-svn] apipkg commit fd590ef45812: make initpkg work without an "old module" in sys.modules
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Nov 4 22:35:01 CET 2010
# HG changeset patch -- Bitbucket.org
# Project apipkg
# URL http://bitbucket.org/hpk42/apipkg/overview
# User Ralf Schmitt <ralf at systemexit.de>
# Date 1288906297 -3600
# Node ID fd590ef45812b3b031ec3412e99b6f03324e9bf9
# Parent 41f548cd98ae6bc5afa5da737730dda749646d76
make initpkg work without an "old module" in sys.modules
--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -400,3 +400,9 @@ def test_aliasmodule_repr():
assert "<AliasModule 'mymod' for 'sys'>" == r
am.version
assert repr(am) == r
+
+def test_initpkg_without_old_module():
+ apipkg.initpkg("initpkg_without_old_module",
+ dict(modules="sys:modules"))
+ from initpkg_without_old_module import modules
+ assert modules is sys.modules
--- a/apipkg.py
+++ b/apipkg.py
@@ -13,7 +13,7 @@ __version__ = "1.2.dev1"
def initpkg(pkgname, exportdefs, attr=dict()):
""" initialize given package from the export definitions. """
- oldmod = sys.modules[pkgname]
+ oldmod = sys.modules.get(pkgname)
d = {}
f = getattr(oldmod, '__file__', None)
if f:
@@ -28,7 +28,8 @@ def initpkg(pkgname, exportdefs, attr=di
if hasattr(oldmod, '__doc__'):
d['__doc__'] = oldmod.__doc__
d.update(attr)
- oldmod.__dict__.update(d)
+ if hasattr(oldmod, "__dict__"):
+ oldmod.__dict__.update(d)
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
sys.modules[pkgname] = mod
More information about the pytest-commit
mailing list