diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index be4d372..93f2792 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -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" diff --git a/tests/test_integration.py b/tests/test_integration.py index c304064..aba3ab8 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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