Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail with weird error if python2 is not installed #24

Open
ukch opened this issue Feb 12, 2019 · 2 comments
Open

Tests fail with weird error if python2 is not installed #24

ukch opened this issue Feb 12, 2019 · 2 comments

Comments

@ukch
Copy link

ukch commented Feb 12, 2019

Describe the bug
Pipes does not require Python 2 to operate. It should not require it for tests, but at present the tests do not pass unless it is installed.

To Reproduce

  • Make sure there is no system python2 executable available
  • Run pytest

Expected behavior
The tests should pass

Actual behaviour
Tests fail with an error like the following:

___________ ERROR at setup of TestFindEnvironments.test_find_binary ____________

request = <FixtureRequest for <Function 'test_find_binary'>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = item.fixturenames
        autousenames = item.session._fixturemanager._getautousenames(item.nodeid)
    
        for fname in fixturenames:
            if fname not in item.funcargs and fname in autousenames:
                item.funcargs[fname] = request.getfixturevalue(fname)
    
        if hasattr(item, 'callspec'):
            for param, val in sorted_by_dependency(item.callspec.params, fixturenames):
                if is_lazy_fixture(val):
                    item.callspec.params[param] = request.getfixturevalue(val.name)
    
>       _fillfixtures()

/usr/lib/python3/dist-packages/pytest_lazyfixture.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/conftest.py:129: in mock_env_home
    envs = find_environments(pipenv_home)
pipenv_pipes/core.py:33: in find_environments
    binpath = find_binary(envpath)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

envpath = '/tmp/pipenv_home_real0cjax3c0/proj1-7PMzaxDr'

    def find_binary(envpath):
        """ Finds the python binary in a given environment path """
        env_ls = os.listdir(envpath)
        if 'bin' in env_ls:
            binpath = os.path.join(envpath, 'bin', 'python')
        elif 'Scripts' in env_ls:
            binpath = os.path.join(envpath, 'Scripts', 'python.exe')
        else:
            raise EnvironmentError(
>               'could not find python binary path: {}'.format(envpath))
E           OSError: could not find python binary path: /tmp/pipenv_home_real0cjax3c0/proj1-7PMzaxDr

pipenv_pipes/core.py:52: OSError
________ ERROR at setup of TestFindEnvironments.test_get_python_version ________

request = <FixtureRequest for <Function 'test_get_python_version'>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = item.fixturenames
        autousenames = item.session._fixturemanager._getautousenames(item.nodeid)
    
        for fname in fixturenames:
            if fname not in item.funcargs and fname in autousenames:
                item.funcargs[fname] = request.getfixturevalue(fname)
    
        if hasattr(item, 'callspec'):
            for param, val in sorted_by_dependency(item.callspec.params, fixturenames):
                if is_lazy_fixture(val):
                    item.callspec.params[param] = request.getfixturevalue(val.name)
    
>       _fillfixtures()

/usr/lib/python3/dist-packages/pytest_lazyfixture.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/conftest.py:129: in mock_env_home
    envs = find_environments(pipenv_home)
pipenv_pipes/core.py:33: in find_environments
    binpath = find_binary(envpath)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

envpath = '/tmp/pipenv_home_realeeyf2spo/proj1-AJFfG1vO'

    def find_binary(envpath):
        """ Finds the python binary in a given environment path """
        env_ls = os.listdir(envpath)
        if 'bin' in env_ls:
            binpath = os.path.join(envpath, 'bin', 'python')
        elif 'Scripts' in env_ls:
            binpath = os.path.join(envpath, 'Scripts', 'python.exe')
        else:
            raise EnvironmentError(
>               'could not find python binary path: {}'.format(envpath))
E           OSError: could not find python binary path: /tmp/pipenv_home_realeeyf2spo/proj1-AJFfG1vO

pipenv_pipes/core.py:52: OSError

After a bit of digging, I managed to trace the problem to the virtualenv creation. The virtualenv command is failing, but because it outputs to stdout the error is being ignored (aside: it would be a good idea to check the error code here instead of just stderr). Then conftest tries to continue without a virtualenv, leading to the error pasted above.

Environment:

  • OS: Debian sid
@ukch
Copy link
Author

ukch commented Feb 12, 2019

One solution to this problem is to change the following:

diff --git a/tests/conftest.py b/tests/conftest.py
index f585016..5d2356c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -39,7 +39,7 @@ def env_vars():
 @pytest.fixture(scope='session')
 def venv_fresh():
     with TemporaryDirectory() as folder:
-        venv_cmd = 'virtualenv --no-pip --no-wheel --no-setuptools'
+        venv_cmd = 'virtualenv --no-pip --no-wheel --no-setuptools --python=python3'
         cmd = '{} {}'.format(venv_cmd, folder)
         proc = Popen(cmd.split(' '), stderr=PIPE, stdout=PIPE)
         out, err = proc.communicate()

@gtalarico
Copy link
Owner

Thanks for digging into this.
Surprised it works on my computer and Ci.
Both have python 2 installed.

Project is py3 only so probably makes sense to explicitly select py3 on venv creation anyhow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants