something strange with setting up virtual environment
I was trying to get the tox based tests running for linux-system-roles.network https://github.com/linux-system-roles/network but when I run tox , the following happens ,(I have put ## before errors so they are a little easier to spot ) black recreate: /home/x/Packages/network/.tox/env-3.6 black installdeps: black black installed: appdirs==1.4.3,attrs==19.3.0,black==19.10b0,click==7.1.1,pathspec==0.7.0,regex==2020.2.20,toml==0.10.0,typed-ast==1.4.1 black run-test-pre: PYTHONHASHSEED='1812900848' black run-test: commands[0] | bash /home/x/Packages/network/.travis/runblack.sh /home/x/Packages/network/.tox/env-3.6/bin/python --check --diff . + /usr/bin/python3.6 -m black --include '^[^.].*\.py$' --exclude '/(\.[^.].*|tests/roles)/' --check --diff . /usr/bin/python3.6: No module named black ##ERROR: InvocationError for command /usr/bin/bash .travis/runblack.sh .tox/env-3.6/bin/python --check --diff . (exited with code 1) pylint recreate: /home/x/Packages/network/.tox/env-2.7 pylint installdeps: colorama, pylint>=1.8.4, ansible, -rpylint_extra_requirements.txt pylint installed: DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support,... pylint run-test-pre: PYTHONHASHSEED='1812900848' pylint run-test: commands[0] | bash /home/x/Packages/network/.travis/runpylint.sh /home/x/Packages/network/.tox/env-2.7/bin/python --errors-only + /home/x/Packages/network/.tox/env-2.7/bin/python /home/x/Packages/network/.travis/custom_pylint.py --errors-only /home/x/Packages/network/.travis/custom_pylint.py: files to be checked: /home/x/Packages/network/tests/unit/test_nm_provider.py /home/x/Packages/network/tests/unit/test_network_connections.py /home/x/Packages/network/tests/ensure_non_running_provider.py /home/x/Packages/network/module_utils/network_lsr/__init__.py /home/x/Packages/network/module_utils/network_lsr/nm_provider.py /home/x/Packages/network/module_utils/network_lsr/argument_validator.py /home/x/Packages/network/module_utils/network_lsr/utils.py /home/x/Packages/network/library/network_connections.py Using config file /home/x/Packages/network/pylintrc flake8 recreate: /home/x/Packages/network/.tox/env-2.7 flake8 installdeps: flake8>=3.5 flake8 installed: DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support,... flake8 run-test-pre: PYTHONHASHSEED='1812900848' flake8 run-test: commands[0] | bash /home/x/Packages/network/.travis/runflake8.sh /home/x/Packages/network/.tox/env-2.7/bin/python --statistics . + /home/x/Packages/network/.tox/env-2.7/bin/python -m flake8 --statistics . py26 create: /home/x/Packages/network/.tox/env-2.6 SKIPPED: InterpreterNotFound: python2.6 py27 recreate: /home/x/Packages/network/.tox/env-2.7 py27 installdeps: pytest-cov, pytest>=3.5.1, mock py27 installed: DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support,... py27 run-test-pre: PYTHONHASHSEED='1812900848' py27 run-test: commands[0] | bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-2.7/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py27 --cov-report=term unit + /home/x/Packages/network/.tox/env-2.7/bin/python -m pytest --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py27 --cov-report=term unit ========================================================================== test session starts ========================================================================== platform linux2 -- Python 2.7.17, pytest-4.6.9, py-1.8.1, pluggy-0.13.1 cachedir: .tox/env-2.7/.pytest_cache rootdir: /home/x/Packages/network, inifile: tox.ini plugins: cov-2.8.1 collected 63 items unit/test_network_connections.py ..........................................................ss.. [ 98%] unit/test_nm_provider.py . [100%] ---------- coverage: platform linux2, python 2.7.17-final-0 ---------- Name Stmts Miss Cover --------------------------------------------------------------------------------------------- /home/x/Packages/network/library/network_connections.py 1397 1122 20% /home/x/Packages/network/module_utils/network_lsr/__init__.py 2 0 100% /home/x/Packages/network/module_utils/network_lsr/argument_validator.py 506 89 82% /home/x/Packages/network/module_utils/network_lsr/nm_provider.py 7 0 100% /home/x/Packages/network/module_utils/network_lsr/utils.py 229 106 54% --------------------------------------------------------------------------------------------- TOTAL 2141 1317 38% Coverage HTML written to dir htmlcov-py27 ======================================================================= slowest 5 test durations ======================================================================== 0.07s call tests/unit/test_network_connections.py::TestUtils::test_check_output 0.03s call tests/unit/test_network_connections.py::TestSysUtils::test_link_read_permaddress 0.01s teardown tests/unit/test_network_connections.py::TestValidator::test_vlan 0.01s call tests/unit/test_network_connections.py::TestValidator::test_macvlan 0.01s call tests/unit/test_network_connections.py::TestValidator::test_vlan ======================================================================== short test summary info ======================================================================== SKIPPED [1] tests/unit/test_network_connections.py:2215: no support for NM (libnm via pygobject) SKIPPED [1] tests/unit/test_network_connections.py:2201: no support for NM (libnm via pygobject) ================================================================= 61 passed, 2 skipped in 2.64 seconds ================================================================== py36 recreate: /home/x/Packages/network/.tox/env-3.6 py36 installdeps: pytest-cov, pytest>=3.5.1 py36 installed: attrs==19.3.0,coverage==5.0.4,importlib-metadata==1.5.0,more-itertools==8.2.0,packaging==20.3,pluggy==0.13.1,py==1.8.1,pyparsing==2.4.6,pytest==5.4.1,pytest-cov==2.8.1,six==1.14.0,wcwidth==0.1.8,zipp==3.1.0 py36 run-test-pre: PYTHONHASHSEED='1812900848' py36 run-test: commands[0] | bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.6/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py36 --cov-report=term unit + /usr/bin/python3.6 -m pytest --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py36 --cov-report=term unit /usr/bin/python3.6: No module named pytest ##ERROR: InvocationError for command /usr/bin/bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.6/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py36 --cov-report=term unit (exited with code 1) py37 installed: attrs==19.3.0,coverage==5.0.4,importlib-metadata==1.5.0,more-itertools==8.2.0,packaging==20.3,pluggy==0.13.1,py==1.8.1,pyparsing==2.4.6,pytest==5.4.1,pytest-cov==2.8.1,six==1.14.0,wcwidth==0.1.8,zipp==3.1.0 py37 run-test-pre: PYTHONHASHSEED='1812900848' py37 run-test: commands[0] | bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.7/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py37 --cov-report=term unit + /usr/bin/python3.7 -m pytest --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py37 --cov-report=term unit ##ERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...] __main__.py: error: unrecognized arguments: --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py37 --cov-report=term inifile: /home/x/Packages/network/tox.ini rootdir: /home/x/Packages/network ERROR: InvocationError for command /usr/bin/bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.7/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py37 --cov-report=term unit (exited with code 4) py38 installed: attrs==19.3.0,coverage==5.0.4,more-itertools==8.2.0,packaging==20.3,pluggy==0.13.1,py==1.8.1,pyparsing==2.4.6,pytest==5.4.1,pytest-cov==2.8.1,six==1.14.0,wcwidth==0.1.8 py38 run-test-pre: PYTHONHASHSEED='1812900848' py38 run-test: commands[0] | bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.8/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py38 --cov-report=term unit + /usr/bin/python3.8 -m pytest --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py38 --cov-report=term unit /usr/bin/python3.8: No module named pytest ##ERROR: InvocationError for command /usr/bin/bash /home/x/Packages/network/.travis/runpytest.sh /home/x/Packages/network/.tox/env-3.8/bin/python --durations=5 --cov=/home/x/Packages/network/library --cov=/home/x/Packages/network/module_utils --cov-report=html:htmlcov-py38 --cov-report=term unit (exited with code 1) custom installed: PyYAML==5.3 custom run-test-pre: PYTHONHASHSEED='1812900848' custom run-test: commands[0] | bash /home/x/Packages/network/.travis/custom.sh /home/x/Packages/network/.tox/env-custom/bin/python /usr/bin/python3 + cd /home/x/Packages/network/tests + /usr/bin/python3.7 ./ensure_non_running_provider.py ________________________________________________________________________________ summary ________________________________________________________________________________ ERROR: black: commands failed pylint: commands succeeded flake8: commands succeeded SKIPPED: py26: InterpreterNotFound: python2.6 py27: commands succeeded ERROR: py36: commands failed ERROR: py37: commands failed ERROR: py38: commands failed custom: commands succeeded I have discussed this problem on the roles list and have tried the suggestions given but nothing seems to be working ,maybe this might help, this is what should happen Well, it is failing even before that. There is something strange going
on with how tox is setting up the virtual environment. The problem is here:
+ /usr/bin/python3.6 -m black --include '^[^.].*\.py$' --exclude '/(\.[^.].*|tests/roles)/' --check --diff . /usr/bin/python3.6: No module named black
That is, it is trying to run the standard system python, outside of the tox virtual environment, so it cannot find the `black` module which was installed into the tox virtual environment.
For example, this is what I see when I run `tox -vvv`:
using tox.ini: /home/rmeggins/linux-system-roles/network/tox.ini (pid 249249) ... black create: /home/rmeggins/linux-system-roles/network/.tox/env-3.6 python3.6 (/usr/bin/python3.6) is {'executable': '/usr/bin/python3.6', 'name': 'python', 'version_info': [3, 6, 10, 'final', 0], 'version': '3.6.10 (default, Dec 20 2019, 00:00:00) \n[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]', 'is_64': True, 'sysplatform': 'linux'} black uses /usr/bin/python3.6 ... setting
PATH=/home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/rmeggins/bin:/home/rmeggins/go/bin [249270] /home/rmeggins/linux-system-roles/network/.tox$ /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3.6 env-3.6 ... New python executable in /home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin/python3.6 Also creating executable in /home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin/python ... This is the key - tox actually creates a python executable in the tox venv. black installdeps: black setting
PATH=/home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/rmeggins/bin:/home/rmeggins/go/bin [249280] /home/rmeggins/linux-system-roles/network$ /home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin/python -m pip install black ... It is now using .tox/env-3.6/bin/python instead of /usr/bin/python3.6 black installed:
appdirs==1.4.3,attrs==19.3.0,black==19.10b0,click==7.1.1,pathspec==0.7.0,regex==2020.2.20,toml==0.10.0,typed-ast==1.4.1 ... black start: run-test black run-test: commands[0] | bash /home/rmeggins/linux-system-roles/network/.travis/runblack.sh /home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin/python --check --diff . setting
PATH=/home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/rmeggins/bin:/home/rmeggins/go/bin [249287] /home/rmeggins/linux-system-roles/network$ /usr/bin/bash .travis/runblack.sh .tox/env-3.6/bin/python --check --diff . + /home/rmeggins/linux-system-roles/network/.tox/env-3.6/bin/python3.6 -m black --include '^[^.].*\.py$' --exclude '/(\.[^.].*|tests/roles)/' --check --diff . All done! ✨ 🍰 ✨
So you can see that the `black` test is using the python exectable from the tox venv .tox/env-3.6/bin/python3.6
I would really appreciate if someone is able to figure out the cause , I have tried installing tox from pip and using the rpm but both yield same results I 'm using a fedora 31 system and have gotten the same error with a manjaro system as well .Please do let me know if anything else is needed Thanks, Harsh
participants (1)
-
Harsh Jain