pytest: --pyargs cannot locate namespace packages installed in editable mode

The --pyargs command-line switch cannot locate libraries within a namespace package that are installed in editable mode.

How to reproduce

  1. In a fresh virtual environment install the attached pinned requirements:

    $ virtualenv env
    $ source env/bin/activate
    $ pip install -r pinned_requirements.txt
    

    This will install three libraries (more.basicauth, more.chameleon, more.forwarded) in editable mode, together with their dependencies.

    These libraries are all defined within the more namespace package.

  2. Run

    $ py.test --pyargs more.chamaleon
    

This is the output I get:

$ py.test --pyargs more.chamaleon
==================================================================== test session starts =====================================================================
platform darwin -- Python 2.7.11, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir:[…]/pytest_bug, inifile: 
plugins: cov-2.2.1

================================================================ no tests ran in 0.00 seconds ================================================================
ERROR: file or package not found: more.chamaleon

Expected output

I expect that py.test invocation to produce similar output as

$ py.test env/src/more.chameleon/more
==================================================================== test session starts =====================================================================
platform darwin -- Python 2.7.11, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: […]/pytest_bug/env/src/more.chameleon, inifile: 
plugins: cov-2.2.1
collected 5 items 

env/src/more.chameleon/more/chameleon/tests/test_chameleon.py .....

================================================================== 5 passed in 0.51 seconds ==================================================================

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 17 (14 by maintainers)

Most upvoted comments

@dimpase indeed we should have this documented somewhere, to avoid users wasting time on this.

Perhaps we can improve the error message:

ERROR: pytest cannot import module or package 'sage.misc'
Possible reasons:
- Missing an __init__.py file
- Namespace package (not supported)
- Not reachable via PYTHONPATH
See <link to docs> for more information.