From a1bd7d9cabd71d0cb3378caf3c41233cacfe406c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 23 Jul 2019 14:37:06 +0200 Subject: [PATCH] Don't blow up on missing interpreter Fixes https://github.com/fedora-python/tox-current-env/issues/5 --- src/tox_current_env/hooks.py | 2 ++ tests/test_integration.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) 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