gpt4 book ai didi

python - 配置 pytest rootdir?

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:23 31 4
gpt4 key购买 nike

我有一个具有以下目录结构的项目:

.
..
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'

我做错了什么?

最佳答案

在运行测试之前,您必须设置PYTHONPATH:

PYTHONPATH=`pwd` pytest

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

pip install -e .
pytest

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

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

或者使用自动创建/激活/停用此类虚拟环境。

关于python - 配置 pytest rootdir?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45417195/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com