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

Fix py27 envs when using tox-venv #21

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test-py27/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tox]
envlist = py27
skipsdist = True

[testenv]
# For https://github.com/pglass/tox-pip-version/issues/20,
# ensure the virtualenv was actually created
commands =
ls {envdir}
ls {envbindir}
stat {envpython}
whitelist_externals =
ls
stat
33 changes: 29 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
},
"test-version-specifiers": {
"env": {},
}
},
"test-py27": {
# So env=None inherits from the parent process, whereas env={} doesn't.
# I have this inherit because it makes pyenv interpreters available and
# we need py27 present for this test.
"env": None,
},
}

PYTEST_PARAMETERS = sorted(itertools.product(TOX_VERSIONS, CASES))
Expand All @@ -63,12 +69,28 @@ def _run_case(venv_dir, subdirectory, env=None):
activate = os.path.join(venv_dir, 'bin', 'activate')
command = '. %s; pip freeze; tox --workdir %s' % (activate, tox_work_dir)
print("Running: '%s'" % command)
subprocess.check_call(command, cwd=directory, shell=True, env=env or {})
subprocess.check_call(command, cwd=directory, shell=True, env=env)


def has_python_exe(exe):
try:
subprocess.check_output([exe, '--version'], stderr=subprocess.PIPE)
return True
except subprocess.CalledProcessError:
return False


def skip_if_missing_python(exe):
if not has_python_exe(exe):
pytest.skip('Python executable %s not found' % exe)


@pytest.mark.parametrize("tox_version,subdirectory", PYTEST_PARAMETERS)
def test_with_tox_version(tox_version, subdirectory):
env = CASES[subdirectory]['env']
if 'py27' in subdirectory:
skip_if_missing_python('python2.7')

env = CASES[subdirectory].get('env')
temp_dir, venv_dir = setup_fresh_venv(tag=subdirectory)
try:
# Sometimes see an error like,
Expand All @@ -89,7 +111,10 @@ def test_with_tox_version(tox_version, subdirectory):

@pytest.mark.parametrize("tox_version,subdirectory", PYTEST_PARAMETERS)
def test_with_tox_version_with_tox_venv(tox_version, subdirectory):
env = CASES[subdirectory]['env']
if 'py27' in subdirectory:
skip_if_missing_python('python2.7')

env = CASES[subdirectory].get('env')
tox_venv_version = TOX_TO_TOX_VENV_VERSIONS[tox_version]

temp_dir, venv_dir = setup_fresh_venv(tag=subdirectory)
Expand Down
11 changes: 8 additions & 3 deletions tox_pip_version/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ def _testenv_create(venv, action):
#
# - detect if tox-venv is installed and invoke if so
# - use `tryfirst=True` on our hookimpl to run before tox-venv does (no
# more plugins after a plugin returns non-None from its hook function)
# plugins run after a plugin returns non-None from its hook function)
try:
from tox_venv.hooks import tox_testenv_create

# tox-venv may not create the venv (like if the venv is python 2)
# so fallback to tox's default
finished = tox_testenv_create(venv, action)
if not finished:
tox.venv.tox_testenv_create(venv, action)
except ImportError:
from tox.venv import tox_testenv_create
tox_testenv_create(venv, action)
tox.venv.tox_testenv_create(venv, action)


def get_pip_package_version(pip_version):
Expand Down