py.test can't resolve imports

Mario Figueiredo marfig at gmail.com
Tue Feb 24 21:37:26 EST 2015


I cannot seem to solve this problem from either the pytest
documentation or from other places on the web which provide tutorials
on pytest, such as http://pythontesting.net/start-here/

I have the following project setup:

    /project
    /project/project    <-- script files (with __init__.py)
    /project/test        <-- test files
    /project/docs       <-- Sphinx

I cannot seem to be able to have py.test resolve imports by running
the following command from within the /project/project directory:

    $ py.test ../


Example scripts:

    /project/project/example.py
    def func():
        pass

    /project/test/test_example.py
    from example import *
    def test_example():
        assert 0

I get an error:

    $ py.test ../

    from example import *
    E   ImportError: No module named 'example'

I can run the tests fine with $ python -m pytest ../

So how do I properly setup if I wish to use the less verbose py.test?



More information about the Python-list mailing list