Skip to content

Commit

Permalink
Remove Python 2 virtualenv tests
Browse files Browse the repository at this point in the history
Resolves python#10407 as well as the mysteriously suddenly broken tests on
master.
  • Loading branch information
hauntsaninja committed Jul 21, 2021
1 parent cae5d3c commit 18ff4c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
23 changes: 5 additions & 18 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down
19 changes: 0 additions & 19 deletions test-data/unit/pep561.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 18ff4c3

Please sign in to comment.