Search code examples
pythonpytesttox

Pytest says 'ModuleNotFoundError' when using tox


I have the following project structure:

root
|- module
  |- module.py
  |- __init__.py
|- tests
   |- unit
      |- some_test.py
   |- integration
      |- another_test.py
|- conftest.py
|- setup.py
|- tox.ini

When I run python3 module/module.py ... it runs as expected.

However, when I execute tox, I get ModuleNotFoundError: No module named 'dateutil'.

In my setup.py I have install_requires=['python-dateutil'] and tox.ini has the following (simplified) contents:

[tox]
envlist   = py{36, 37}
skipsdist = True

[testenv]
deps = pytest
commands = pytest

Does anyone have any insight as to why running tox gives me that the module 'dateutil' cannot be found and how to fix it?


Solution

  • [tox]skipsdist = True prevents tox to run python setup.py sdist so your install_requires is completely ignored.

    If you really want to follow the advice to set [tox]skipsdist = True for applications you are also advised to follow all other best practices for packaging applications: use requirements.txt and add

    [testenv]
    deps =
        -rrequirements.txt
    

    to tox.ini. Or just directly

    [testenv]
    deps = python-dateutil