Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pytest正在搜索更高级别的测试_Python_Pytest - Fatal编程技术网

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
s
pytest
将进入父目录,查找
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