From 18ff4c31c8c23710d42da002099584e4f6e9ecec Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 20 Jul 2021 21:11:27 -0700 Subject: [PATCH] Remove Python 2 virtualenv tests Resolves #10407 as well as the mysteriously suddenly broken tests on master. --- mypy/test/testpep561.py | 23 +++++------------------ test-data/unit/pep561.test | 19 ------------------- test-requirements.txt | 1 - 3 files changed, 5 insertions(+), 38 deletions(-) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index ba5be621e066..00c3b124fe11 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -6,11 +6,11 @@ from subprocess import PIPE import sys import tempfile +import venv from typing import Tuple, List, Generator 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 @@ -49,18 +49,10 @@ def virtualenv( ) -> Generator[Tuple[str, str], None, None]: """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) - 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) + venv.create(venv_dir, with_pip=True, clear=True) if sys.platform == 'win32': yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python')) else: @@ -96,12 +88,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/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