2017-07-31 158 views
1

我有具有以下目录结构的项目:配置pytest rootdir?

. 
.. 
core/start.py 
tests/test_curve.py 
pytest.ini 

pytest.ini的内容是:

[pytest] 
testpaths = tests 

test_curve.py内容是:

import core.start 

def test_curve(): 
    assert some_valid_stuff 

当我跑项目的根文件夹pytest,我得到:

import core.start 
ImportError: No module named 'core' 

我在做什么错?

+0

这不是pytest问题,但蟒蛇进口。 'core'和'tests'不是来自同一个软件包,所以你不能''import core.start' from'core import start' – Arount

回答

1

你必须在运行测试之前设置PYTHONPATH

PYTHONPATH=`pwd` pytest 

或者在开发者的模式下安装代码:

pip install -e . 
pytest 

或运行安装了代码的虚拟环境中的测试:

virtualenv mycode 
. mycode/bin/activate 
pip install . 
pytest 
deactivate 

或使用创建/激活/自动禁用这些虚拟环境。