python - Pytest 在使用 tox 时说 'ModuleNotFoundError'

标签 python pytest tox

我有以下项目结构:

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/

相关文章:

python - 如何在没有 DFS/BFS 的情况下枚举哈密顿循环的可能重建?

python - Django:在 models.filefield(upload_to) 位置访问主键

python - mock 父类

python - 我可以让 pytest doctest 模块忽略一个文件吗?

python - 用于测试包的基本毒理学设置

python - 如何不在 QHBoxLayout 中分隔小部件

python - 如何在 anaconda 中卸载单个包?

python - 具有全局固定装置时,如何将 Python 单元测试转换为 pytest?

python - 在特定版本中测试 python 脚本

python - 属性错误: module 'tox.config' has no attribute 'parseini'