Skip to content

Commit a2b2e3f

Browse files
author
hauntsaninja
committed
fix test
1 parent 18ff4c3 commit a2b2e3f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

mypy/test/testpep561.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from subprocess import PIPE
77
import sys
88
import tempfile
9-
import venv
10-
from typing import Tuple, List, Generator
9+
from typing import Tuple, List, Iterator
1110

1211
import mypy.api
1312
from mypy.test.config import package_path
@@ -44,15 +43,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None:
4443

4544

4645
@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]]:
5047
"""Context manager that creates a virtualenv in a temporary directory
5148
5249
Returns the path to the created Python executable
5350
"""
5451
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)
5659
if sys.platform == 'win32':
5760
yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python'))
5861
else:

mypyc/test-data/run-imports.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def test_import_as_submodule_within_function() -> None:
3030
# assert 'nob' not in globals()
3131

3232
def test_import_module_without_stub_in_function() -> None:
33-
# 'virtualenv' must not have a stub in typeshed for this test case
34-
import virtualenv # type: ignore
33+
# 'psutil' must not have a stub in typeshed for this test case
34+
import psutil # type: ignore
3535
# TODO: We shouldn't add local imports to globals()
36-
# assert 'virtualenv' not in globals()
37-
assert isinstance(virtualenv.__name__, str)
36+
# assert 'psutil' not in globals()
37+
assert isinstance(psutil.__name__, str)
3838

3939
def test_import_as_module_without_stub_in_function() -> None:
40-
# 'virtualenv' must not have a stub in typeshed for this test case
41-
import virtualenv as vv # type: ignore
42-
assert 'virtualenv' not in globals()
40+
# 'psutil' must not have a stub in typeshed for this test case
41+
import psutil as pp # type: ignore
42+
assert 'psutil' not in globals()
4343
# TODO: We shouldn't add local imports to globals()
44-
# assert 'vv' not in globals()
45-
assert isinstance(vv.__name__, str)
44+
# assert 'pp' not in globals()
45+
assert isinstance(pp.__name__, str)
4646

4747
[file testmodule.py]
4848
def factorial(x: int) -> int:

0 commit comments

Comments
 (0)