Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest says 'ModuleNotFoundError' when using tox

Tags:

python

pytest

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?

like image 407
Max Power Avatar asked Feb 05 '19 11:02

Max Power


2 Answers

[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
like image 77
phd Avatar answered Nov 13 '22 08:11

phd


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
like image 42
Fedorov7890 Avatar answered Nov 13 '22 09:11

Fedorov7890