|
6 | 6 | from subprocess import PIPE
|
7 | 7 | import sys
|
8 | 8 | import tempfile
|
9 |
| -import venv |
10 |
| -from typing import Tuple, List, Generator |
| 9 | +from typing import Tuple, List, Iterator |
11 | 10 |
|
12 | 11 | import mypy.api
|
13 | 12 | from mypy.test.config import package_path
|
@@ -44,15 +43,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None:
|
44 | 43 |
|
45 | 44 |
|
46 | 45 | @contextmanager
|
47 |
| -def virtualenv( |
48 |
| - python_executable: str = sys.executable |
49 |
| - ) -> Generator[Tuple[str, str], None, None]: |
| 46 | +def virtualenv(python_executable: str = sys.executable) -> Iterator[Tuple[str, str]]: |
50 | 47 | """Context manager that creates a virtualenv in a temporary directory
|
51 | 48 |
|
52 | 49 | Returns the path to the created Python executable
|
53 | 50 | """
|
54 | 51 | with tempfile.TemporaryDirectory() as venv_dir:
|
55 |
| - venv.create(venv_dir, with_pip=True, clear=True) |
| 52 | + proc = subprocess.run( |
| 53 | + [python_executable, '-m', 'venv', venv_dir], |
| 54 | + cwd=os.getcwd(), stdout=PIPE, stderr=PIPE |
| 55 | + ) |
| 56 | + if proc.returncode != 0: |
| 57 | + err = proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8') |
| 58 | + raise Exception("Failed to create venv.\n" + err) |
56 | 59 | if sys.platform == 'win32':
|
57 | 60 | yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python'))
|
58 | 61 | else:
|
|
0 commit comments