Home > Blockchain >  In tox testenv "ModuleNotFoundError: No module named 'pandas" error comes whenever pa
In tox testenv "ModuleNotFoundError: No module named 'pandas" error comes whenever pa

Time:11-21

After I implemented my test, which is using pandas, my build is failing with "ModuleNotFoundError: No module named 'pandas'" error, however, I added pandas to the testenv deps and in the log file I also see that it is installed. I got the same error in case of boto3 but after I added it to the deps, it solved the problem but in case of pandas it doesn't work.

tox.ini

[tox]         
envlist=flake8
        py36_tests

[testenv]
deps=pytest
     flake8

[testenv:py36_tests]
basepython=python3.6
deps=boto3
     pandas
commands=py.test -s -v tests --junitxml=report.xml

[testenv:flake8]
commands=flake8 --exclude=.git,__pycache__,__init__.py data_collector/
         flake8 tests/
         flake8 setup.py
         flake8 setup-cy.py
         flake8 Docker/startup_scripts/
         flake8 bin/data_collector

Log:

$ tox -e py36_tests
GLOB sdist-make: /builds/<path>/<my_package>/setup.py
py36_tests create: /builds/<path>/<my_package>/.tox/py36_tests
py36_tests installdeps: boto3, pandas
py36_tests inst: /builds/<path>/.tox/.tmp/package/1/<my_package>-0.0.0.zip
py36_tests installed: <many packages>, pandas==1.1.1, <many packages>
y36_tests run-test-pre: PYTHONHASHSEED='3745093701'
py36_tests run-test: commands[0] | py.test -s -v tests --junitxml=report.xml
WARNING: test command found but not installed in testenv
  cmd: /usr/local/bin/py.test
  env: /builds/<path>/<my_package>/.tox/py36_tests
Maybe you forgot to specify a dependency? See also the allowlist_externals envconfig setting.
DEPRECATION WARNING: this will be an error in tox 4 and above!
============================= test session starts ==============================
platform linux -- Python 3.6.15, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3.6
cachedir: .tox/py36_tests/.pytest_cache
rootdir: /builds/<path>/<my_package>
collecting ... collected 10 items / 1 error / 9 selected
==================================== ERRORS ====================================
________________ ERROR collecting tests/ingestion/test_task.py _________________
ImportError while importing test module '/builds/<path>/tests/ingestion/test_task.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/ingestion/test_task.py:3: in <module>
    import pandas as pd
E   ModuleNotFoundError: No module named 'pandas'
- generated xml file: /builds/<path>/<my_package>/report.xml -
=========================== short test summary info ============================
ERROR tests/ingestion/test_task.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.24s ===============================
ERROR: InvocationError for command /usr/local/bin/py.test -s -v tests --junitxml=report.xml (exited with code 2)
___________________________________ summary ____________________________________
ERROR:   py36_tests: commands failed

While I hadn't got any import in my test it worked well. What is the problem?

CodePudding user response:

See this

WARNING: test command found but not installed in testenv
  cmd: /usr/local/bin/py.test

You have not installed py.test into the virtual environment so tox found a global one. And of course the global one runs with a global Python and doesn't know anything about your virtual environments in tox.

To fix it install pytest into the virtual environment:

[testenv:py36_tests]
deps=boto3
     pandas
     pytest

CodePudding user response:

I used a virtual env after the tox call, the solution was to move the tox call when the virtual env was already activated.

  • Related