Python Pytest正在搜索更高级别的测试
我试图在一台机器上运行Python Pytest正在搜索更高级别的测试,python,pytest,Python,Pytest,我试图在一台机器上运行pytest,但pytest使采购conftest更高一级。我正在使用的目录没有\uuuuu init\uuuuuuu.py 17:09:36 /shared/functionaltests/kubernetesTests 17:09:36 + rm __init__.py 17:09:36 + ls 17:09:36 conftest.py 17:09:36 helper_functions.py 17:09:36 kubernetesTests.groovy
pytest
,但pytest
使采购conftest
更高一级。我正在使用的目录没有\uuuuu init\uuuuuuu.py
17:09:36 /shared/functionaltests/kubernetesTests
17:09:36 + rm __init__.py
17:09:36 + ls
17:09:36 conftest.py
17:09:36 helper_functions.py
17:09:36 kubernetesTests.groovy
17:09:36 readme.txt
17:09:36 test_complete.py
17:09:36 + pytest ./
17:09:36 ImportError while loading conftest '/shared/functionaltests/conftest.py'.
17:09:36 ../conftest.py:8: in <module>
17:09:36 import functionaltests.panda_functions as pf
17:09:36 ../panda_functions.py:1: in <module>
17:09:36 import pandas
17:09:36 E ModuleNotFoundError: No module named 'pandas'
-Removed __init__.py
-launching pytest using py.test and python -m pytest
-using --rootdir=./
17:09:36/shared/functionaltests/kubernetests
17:09:36+rm\uuuuuuuuuuuu init.py
17:09:36+ls
17:09:36 conftest.py
17:09:36 helper_functions.py
17:09:36 kubernetesTests.groovy
17:09:36 readme.txt
17:09:36测试完成.py
17:09:36+pytest/
17:09:36加载conftest'/shared/functionaltests/conftest.py'时导入错误。
17:09:36../conftest.py:8:in
17:09:36导入函数tests.panda_用作pf
17:09:36../panda_函数。py:1:in
17:09:36进口大熊猫
17:09:36 E ModuleNotFoundError:没有名为“pandas”的模块
-已删除\uuuu init\uuuuuu.py
-使用py.test和python-m pytest启动pytest
-使用--rootdir=/
这是一种预期行为,因为您没有明确指定根目录是什么(例如,在目录中放置pytest.ini
),并在父目录中放置conftest.py
spytest
将进入父目录,查找pytest.ini
,将遇到conftest.py
并将目录作为rootdir本身或rootdir的子目录。如果要使kubernetesTests
成为rootdir,请在其中放置一个空的pytest.ini
:
touch /shared/functionaltests/kubernetesTests/pytest.ini`
现在将不会加载父级conftest
s
另一种解决方案是通过将/shared
添加到sys.path
来修复导入:
PYTHONPATH=/shared pytest
现在/shared
仍然是rootdir(它应该是这样的),并且加载并执行父conftest.py
s