diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index ba5be621e066..bd2d4d2cea71 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -6,11 +6,10 @@ from subprocess import PIPE import sys import tempfile -from typing import Tuple, List, Generator +from typing import Tuple, List, Iterator import mypy.api from mypy.test.config import package_path -from mypy.util import try_find_python2_interpreter from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.config import test_temp_dir from mypy.test.helpers import assert_string_arrays_equal @@ -44,23 +43,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None: @contextmanager -def virtualenv( - python_executable: str = sys.executable - ) -> Generator[Tuple[str, str], None, None]: +def virtualenv(python_executable: str = sys.executable) -> Iterator[Tuple[str, str]]: """Context manager that creates a virtualenv in a temporary directory - returns the path to the created Python executable""" - # Sadly, we need virtualenv, as the Python 3 venv module does not support creating a venv - # for Python 2, and Python 2 does not have its own venv. + Returns the path to the created Python executable + """ with tempfile.TemporaryDirectory() as venv_dir: - proc = subprocess.run([sys.executable, - '-m', - 'virtualenv', - '-p{}'.format(python_executable), - venv_dir], cwd=os.getcwd(), stdout=PIPE, stderr=PIPE) + proc = subprocess.run( + [python_executable, '-m', 'venv', venv_dir], + cwd=os.getcwd(), stdout=PIPE, stderr=PIPE + ) if proc.returncode != 0: err = proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8') - raise Exception("Failed to create venv. Do you have virtualenv installed?\n" + err) + raise Exception("Failed to create venv.\n" + err) if sys.platform == 'win32': yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python')) else: @@ -96,12 +91,7 @@ def test_pep561(testcase: DataDrivenTestCase) -> None: sys.base_prefix != sys.prefix): pytest.skip() assert testcase.old_cwd is not None, "test was not properly set up" - if 'python2' in testcase.name.lower(): - python = try_find_python2_interpreter() - if python is None: - pytest.skip() - else: - python = sys.executable + python = sys.executable assert python is not None, "Should be impossible" pkgs, pip_args = parse_pkgs(testcase.input[0]) mypy_args = parse_mypy_args(testcase.input[1]) diff --git a/mypyc/test-data/run-imports.test b/mypyc/test-data/run-imports.test index 0957d1b2b87f..c6d5bdb3d864 100644 --- a/mypyc/test-data/run-imports.test +++ b/mypyc/test-data/run-imports.test @@ -30,19 +30,19 @@ def test_import_as_submodule_within_function() -> None: # assert 'nob' not in globals() def test_import_module_without_stub_in_function() -> None: - # 'virtualenv' must not have a stub in typeshed for this test case - import virtualenv # type: ignore + # 'psutil' must not have a stub in typeshed for this test case + import psutil # type: ignore # TODO: We shouldn't add local imports to globals() - # assert 'virtualenv' not in globals() - assert isinstance(virtualenv.__name__, str) + # assert 'psutil' not in globals() + assert isinstance(psutil.__name__, str) def test_import_as_module_without_stub_in_function() -> None: - # 'virtualenv' must not have a stub in typeshed for this test case - import virtualenv as vv # type: ignore - assert 'virtualenv' not in globals() + # 'psutil' must not have a stub in typeshed for this test case + import psutil as pp # type: ignore + assert 'psutil' not in globals() # TODO: We shouldn't add local imports to globals() - # assert 'vv' not in globals() - assert isinstance(vv.__name__, str) + # assert 'pp' not in globals() + assert isinstance(pp.__name__, str) [file testmodule.py] def factorial(x: int) -> int: diff --git a/test-data/unit/pep561.test b/test-data/unit/pep561.test index a4f96ede9f41..e336e92f6dec 100644 --- a/test-data/unit/pep561.test +++ b/test-data/unit/pep561.test @@ -72,25 +72,6 @@ reveal_type(a) [out] testStubPrecedence.py:5: note: Revealed type is "builtins.list[builtins.str]" -[case testTypedPkgStubs_python2] -# pkgs: typedpkg-stubs -from typedpkg.sample import ex -from typedpkg import dne -a = ex(['']) -reveal_type(a) -[out] -testTypedPkgStubs_python2.py:3: error: Module "typedpkg" has no attribute "dne" -testTypedPkgStubs_python2.py:5: note: Revealed type is "builtins.list[builtins.str]" - -[case testTypedPkgSimple_python2] -# pkgs: typedpkg -from typedpkg.sample import ex -from typedpkg import dne -a = ex(['']) -reveal_type(a) -[out] -testTypedPkgSimple_python2.py:5: note: Revealed type is "builtins.tuple[builtins.str]" - [case testTypedPkgSimpleEgg] # pkgs: typedpkg; no-pip from typedpkg.sample import ex diff --git a/test-requirements.txt b/test-requirements.txt index b5b9da8b0a24..245d644288c2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,6 +12,5 @@ pytest-forked>=1.3.0,<2.0.0 pytest-cov>=2.10.0,<3.0.0 typing>=3.5.2; python_version < '3.5' py>=1.5.2 -virtualenv<20 setuptools!=50 importlib-metadata==0.20