make inspect.getsource work for standalone py.test by implementing a get_source method on our DictImporter.

--HG--
branch : trunk
This commit is contained in:
Ralf Schmitt 2009-12-30 19:01:46 +01:00
parent a42d9eb9f6
commit 1103f2ad62
2 changed files with 9 additions and 0 deletions

View File

@ -47,6 +47,14 @@ class DictImporter(object):
do_exec(co, module.__dict__)
return sys.modules[fullname]
def get_source(self, name):
res = self.sources.get(name)
if res is None:
res = self.sources.get(name+'.__init__')
return res
importer = DictImporter()
sys.meta_path.append(importer)

View File

@ -17,6 +17,7 @@ def initpkg(pkgname, exportdefs):
mod.__file__ = getattr(oldmod, '__file__', None)
mod.__version__ = getattr(oldmod, '__version__', None)
mod.__path__ = getattr(oldmod, '__path__', None)
mod.__loader__ = getattr(oldmod, '__loader__', None)
sys.modules[pkgname] = mod
def importobj(modpath, attrname):