[TIP] py.test and Namespace Package issue

Tom Davis tom at recursivedream.com
Tue Feb 26 07:21:14 PST 2013


I have a couple 2.7-style namespace packages, call 'em:

    foo.web
    foo.api

Now, say I symlink web then api:

    cd ~/foo/{web,api} && python setup.py develop

If I now do `py.test --pyargs foo.web.tests`, the tests will fail with
"ImportError: No module named web.tests.conftest". However! Either of
these work fine:

    python -mpytest
    python setup.py test

I narrowed this down to `py._path.pyimport()` and found that if I
ensured that `pkgpath` is always `None`, it works. Oddly, all three
methods appear to be going through the same code path.

I also discovered that deleting __init__.py from the `tests` directories
also fixed it.

I'm not sure if this is a bug or just an oddity of namespace packages.



More information about the testing-in-python mailing list