我有以下项目结构:
root
|- module
|- module.py
|- __init__.py
|- tests
|- unit
|- some_test.py
|- integration
|- another_test.py
|- conftest.py
|- setup.py
|- tox.ini
当我运行 python3 module/module.py ...
时,它按预期运行。
但是,当我执行 tox
时,我得到了 ModuleNotFoundError: No module named 'dateutil'
。
在我的 setup.py 中,我有 install_requires=['python-dateutil']
并且 tox.ini 有以下(简化的)内容:
[tox]
envlist = py{36, 37}
skipsdist = True
[testenv]
deps = pytest
commands = pytest
有没有人知道为什么运行 tox
会给我找不到模块“dateutil”以及如何修复它?
最佳答案
[tox]skipsdist = True
prevents tox
运行 python setup.py sdist
所以你的 install_requires
被完全忽略。
如果您真的想按照建议为应用程序设置 [tox]skipsdist = True
,还建议您遵循打包应用程序的所有其他最佳实践:使用 requirements.txt
并添加
[testenv]
deps =
-rrequirements.txt
到 tox.ini
。或者直接
[testenv]
deps = python-dateutil
关于python - Pytest 在使用 tox 时说 'ModuleNotFoundError',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54532961/