1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2024-12-24 17:16:13 +01:00

Don't blow up on missing interpreter

Fixes https://github.com/fedora-python/tox-current-env/issues/5
This commit is contained in:
Miro Hrončok 2019-07-23 14:37:06 +02:00
parent 3bca04c780
commit a1bd7d9cab
2 changed files with 21 additions and 0 deletions

View File

@ -46,6 +46,8 @@ def tox_testenv_create(venv, action):
return True
if config.option.current_env:
version_info = venv.envconfig.python_info.version_info
if version_info is None:
raise tox.exception.InterpreterNotFound(venv.envconfig.basepython)
if version_info[:2] != sys.version_info[:2]:
raise InterpreterMismatch(
f"tox_current_env: interpreter versions do not match:\n"

View File

@ -27,6 +27,14 @@ def tox(*args, prune=True, **kwargs):
return cp
def is_available(python):
try:
subprocess.run((python, "--version"))
except FileNotFoundError:
return False
return True
def test_native_toxenv_current_env():
result = tox("-e", NATIVE_TOXENV, "--current-env")
assert result.stdout.splitlines()[0] == NATIVE_EXECUTABLE
@ -40,6 +48,17 @@ def test_all_toxenv_current_env():
assert result.returncode > 0
@pytest.mark.parametrize("python", ["python3.4", "python3.5"])
def test_missing_toxenv_current_env(python):
if is_available(python):
pytest.skip(f"Only works if {python} is not available in $PATH")
env = python.replace("python", "py").replace(".", "")
result = tox("-e", env, "--current-env", check=False)
assert f"InterpreterNotFound: {python}" in result.stdout
assert "Traceback" not in (result.stderr + result.stdout)
assert result.returncode > 0
def test_all_toxenv_current_env_skip_missing():
result = tox("--current-env", "--skip-missing-interpreters", check=False)
assert "InterpreterMismatch:" in result.stdout