我尝试运行时收到以下错误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
Run Code Online (Sandbox Code Playgroud)
我的回购结构是
lib/
-tests/
-test_file.py
app/
-test_settings.py
pytest.ini
conftest.py
...
Run Code Online (Sandbox Code Playgroud)
其他人运行此代码很好,根据这个问题(和这个),我的结构很好,我不缺少任何文件.我只能得出结论,关于我的计算机或项目设置是不对的.如果您有任何我可能遗失的建议或见解,请将其发送给我们!
- - - - - - - - - - - - - - - -更多细节 - - - - - - - - - -------------
test_file.py:
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
Run Code Online (Sandbox Code Playgroud)
pytest.ini:
[pytest]
DJANGO_SETTINGS_MODULE = app.test_settings
python_files = tests.py test_* *_tests.py *test.py
Run Code Online (Sandbox Code Playgroud)
Lis*_*saD 45
我也有docker以及在docker之外运行pytest,对我来说,一个影响小得多的修复程序,只要删除所有已编译的python文件
find . -name \*.pyc -delete
| 归档时间: |
|
| 查看次数: |
5824 次 |
| 最近记录: |