我试图在一台机器上运行pytest
,但是pytest
将conftest
的寻源级别提高了一个级别。我使用的目录没有__init__.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=./
这是一种预期的行为,因为您没有显式指定根目录是什么(例如,在目录中放入
pytest.ini
),而在父目录中放入conftest.py
。pytest
将进入父目录,查找pytest.ini
,将遇到conftest.py
,并将目录计数为rootdir本身或rootdir的子目录。如果要使kubernetesTests
成为rootdir,请在其中放置一个空的pytest.ini
:现在不会加载父级
conftest
。你知道吗另一种解决方案是通过将
/shared
添加到sys.path
来修复导入:现在
/shared
仍然是rootdir(它应该是这样的),并且父conftest.py
被加载并执行。你知道吗相关问题 更多 >
编程相关推荐