Get interpreter environment tests working

This commit is contained in:
Dave Halter
2020-01-12 20:19:33 +01:00
parent 591e3c4565
commit c56dae4835
2 changed files with 18 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import os
import sys
import subprocess
from itertools import count
@@ -7,12 +8,19 @@ import pytest
from . import helpers
from . import run
from . import refactor
from jedi.api.environment import InterpreterEnvironment
from jedi.api.environment import InterpreterEnvironment, get_system_environment
from jedi.inference.compiled.value import create_from_access_path
from jedi.inference.imports import _load_python_module
from jedi.file_io import KnownContentFileIO
from jedi.inference.base_value import ValueSet
# For interpreter tests sometimes the path of this directory is in the sys
# path, which we definitely don't want. So just remove it globally.
try:
sys.path.remove(helpers.test_dir)
except ValueError:
pass
def pytest_addoption(parser):
parser.addoption(
@@ -93,9 +101,15 @@ def collect_static_analysis_tests(base_dir, test_files):
def venv_path(tmpdir_factory, environment):
if environment.version_info.major < 3:
pytest.skip("python -m venv does not exist in Python 2")
elif isinstance(environment, InterpreterEnvironment):
# The environment can be a tox virtualenv environment which we don't
# want, so use the system environment.
environment = get_system_environment(
'.'.join(str(x) for x in environment.version_info[:2])
)
tmpdir = tmpdir_factory.mktemp('venv_path')
dirname = os.path.join(tmpdir.dirname, 'venv')
dirname = os.path.join(tmpdir.strpath, 'venv')
# We cannot use the Python from tox because tox creates virtualenvs and
# they have different site.py files that work differently than the default
@@ -113,7 +127,8 @@ def venv_path(tmpdir_factory, environment):
executable_name = os.path.basename(environment.executable)
executable_path = os.path.join(prefix, 'bin', executable_name)
subprocess.call([executable_path, '-m', 'venv', dirname])
return_code = subprocess.call([executable_path, '-m', 'venv', dirname])
assert return_code == 0, return_code
return dirname