gpt4 book ai didi

pytest "Error: could not load path/to/conftest.py"

转载 作者:行者123 更新时间:2023-12-03 15:08:45 24 4
gpt4 key购买 nike

当我尝试运行 pytest repo/tests/test_file.py 时出现以下错误:

$ pytest repo/tests/test_file.py
Traceback (most recent call last):
File "/Users/marlo/anaconda3/envs/venv/lib/python3.6/site-packages/_pytest/config.py", line 329, in _getconftestmodules
return self._path2confmods[path]
KeyError: local('/Users/marlo/repo/tests/test_file.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/marlo/anaconda3/envs/venv/lib/python3.6/site-packages/_pytest/config.py", line 329, in _getconftestmodules
return self._path2confmods[path]
KeyError: local('/Users/marlo/repo/tests')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/marlo/anaconda3/envs/venv/lib/python3.6/site-packages/_pytest/config.py", line 362, in _importconftest
return self._conftestpath2mod[conftestpath]
KeyError: local('/Users/marlo/repo/conftest.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/marlo/anaconda3/envs/venv/lib/python3.6/site-packages/_pytest/config.py", line 368, in _importconftest
mod = conftestpath.pyimport()
File "/Users/marlo/anaconda3/envs/venv/lib/python3.6/site-packages/py/_path/local.py", line 686, in pyimport
raise self.ImportMismatchError(modname, modfile, self)
py._path.local.LocalPath.ImportMismatchError: ('conftest', '/home/venvuser/venv/conftest.py', local('/Users/marlo/repo/conftest.py'))
ERROR: could not load /Users/marlo/repo/conftest.py

我的 repo 结构是
lib/
-tests/
-test_file.py
app/
-test_settings.py
pytest.ini
conftest.py
...

其他人已经很好地运行了这段代码,根据 this question (和 this one ),我的结构很好,我没有丢失任何文件。我只能得出结论,我的计算机或项目设置有问题。如果您有任何我可能遗漏的建议或见解,请将它们发送给我!

- - - - - - - - - - - - - - - -更多细节 - - - - - - - - - -------------

test_file.py :
def func(x):
return x + 1

def test_answer():
assert func(3) == 5

pytest.ini :
[pytest]
DJANGO_SETTINGS_MODULE = app.test_settings
python_files = tests.py test_* *_tests.py *test.py

最佳答案

我有 docker 以及在 docker 之外运行 pytest,对我来说,每当出现这种情况时,影响低得多的修复是删除所有已编译的 python 文件
find . -name \*.pyc -delete

关于pytest "Error: could not load path/to/conftest.py",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48696021/

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