[py-dev] py.path import hook for getpymodule()

Armin Rigo arigo at tunes.org
Tue Nov 9 14:47:29 CET 2004


Hi Holger,

On Tue, Nov 09, 2004 at 12:14:20PM +0100, holger krekel wrote:
> IOW, I'd actually like to apply getpymodule() semantics to a whole
> package, e.g. the py lib itself. For such cases we might even
> refuse to defer to the standard import mechanism.  i.e. when one does
> 
>  mypkg/__init__.py 
>     from py.initpkg import initpkg 
>     initpkg.initpkg(__name__, {...}) 
> 
> then we would eventually refuse to fall back to the cpython standard import hook 
> for any import below 'mypkg.*'.

Sounds pretty much reasonable.

> Of course, if you don't apply initpkg() then your above view of separation 
> between tests and the rest of your package should still be true. 

Actually, in that view, the test files would contain import statements to
import the package they test; such import statements would then be
getpymodule()ed as well, so that the current result with py.test is that the
py lib and stdlib are loaded using CPython's import and all the tested user
code is loaded with getpymodule(), which is nice too.  Allowing the py lib
itself to be loaded with getpymodule() too is a separate issue, though it
would be nice as well.


Armin



More information about the Pytest-dev mailing list