14

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?

Max Power
  • 952
  • 9
  • 24

3 Answers3

13

[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
phd
  • 82,685
  • 13
  • 120
  • 165
6

What helped me:

  1. Add missing modules to the install_requires section of the setup.py
  2. Delete old .tox directory and re-run tox
Fedorov7890
  • 1,173
  • 13
  • 28
2

If none of the answers dated before my post works, try this answer from Jürgen Gmach, which states the below:

tox version 4 has been released a couple of weeks ago.

There were a couple of breaking changes, see https://tox.wiki/en/latest/faq.html#breaking-changes-in-tox-4

I would recommend to create an issue at https://github.com/tox-dev/tox/issues

In the meantime, to get your CI unblocked, I would recommend to pin tox < 4 in your github actions.

jsibs
  • 666
  • 2
  • 7
  • 25