尝试运行$ 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
时出现以下错误:
lib/
-tests/
-test_file.py
app/
-test_settings.py
pytest.ini
conftest.py
...
我的回购结构是
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
其他人运行此代码很好,根据this question(和this one),我的结构很好,我不会遗漏任何文件。我只能得出结论,关于我的计算机或项目设置是不对的。如果您有任何我可能遗失的建议或见解,请将其发送给我们!
-------------------------------更多详情-------------- ----------------
test_file.py :
[pytest]
DJANGO_SETTINGS_MODULE = app.test_settings
python_files = tests.py test_* *_tests.py *test.py
pytest.ini :
{{1}}
答案 0 :(得分:37)
我也有docker以及在docker之外运行pytest,对我来说,只要删除所有已编译的python文件就会产生影响较小的修复程序
find . -name \*.pyc -delete
答案 1 :(得分:1)
我想出来了,如果其他人有同样的问题,我会回答:
我甚至没有考虑到我在repo目录中有一个docker容器(同一个应用程序),虽然我没有运行docker容器,但它以某种方式影响了文件路径。
解决此问题:
$ conda env update --name project --file project.yml
$ dropdb projectdb $ createdb projectdb
$ mongo projectdb --eval "db.dropDatabase()"
pytest
$ pip uninstall pytest $ pip install pytest
......瞧!我可以运行pytest。
非常感谢@hoefling和其他帮助我调试的人。