Skip to content

Commit 05c2d21

Browse files
committed
Add tests for python_requires
and cleanup when install is aborted
1 parent 2df0ea9 commit 05c2d21

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

pip/req/req_set.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ def _prepare_file(self,
665665
if self.ignore_requires_python:
666666
logger.warning(e.args[0])
667667
else:
668+
req_to_install.remove_temporary_source()
668669
raise
669670
more_reqs = []
670671

tests/functional/test_install.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,3 +1076,67 @@ def test_double_install_fail(script, data):
10761076
msg = ("Double requirement given: pip==7.1.2 (already in pip==*, "
10771077
"name='pip')")
10781078
assert msg in result.stderr
1079+
1080+
1081+
def test_install_incompatible_python_requires(script):
1082+
script.scratch_path.join("pkga").mkdir()
1083+
pkga_path = script.scratch_path / 'pkga'
1084+
pkga_path.join("setup.py").write(textwrap.dedent("""
1085+
from setuptools import setup
1086+
setup(name='pkga',
1087+
python_requires='<1.0',
1088+
version='0.1')
1089+
"""))
1090+
script.pip('install', 'setuptools>24.2') # This should not be needed
1091+
result = script.pip('install', pkga_path, expect_error=True)
1092+
assert ("pkga requires Python '<1.0' "
1093+
"but the running Python is ") in result.stderr
1094+
1095+
1096+
def test_install_incompatible_python_requires_editable(script):
1097+
script.scratch_path.join("pkga").mkdir()
1098+
pkga_path = script.scratch_path / 'pkga'
1099+
pkga_path.join("setup.py").write(textwrap.dedent("""
1100+
from setuptools import setup
1101+
setup(name='pkga',
1102+
python_requires='<1.0',
1103+
version='0.1')
1104+
"""))
1105+
script.pip('install', 'setuptools>24.2') # This should not be needed
1106+
result = script.pip(
1107+
'install', '--editable=%s' % pkga_path, expect_error=True)
1108+
assert ("pkga requires Python '<1.0' "
1109+
"but the running Python is ") in result.stderr
1110+
1111+
1112+
def test_install_incompatible_python_requires_wheel(script):
1113+
script.scratch_path.join("pkga").mkdir()
1114+
pkga_path = script.scratch_path / 'pkga'
1115+
pkga_path.join("setup.py").write(textwrap.dedent("""
1116+
from setuptools import setup
1117+
setup(name='pkga',
1118+
python_requires='<1.0',
1119+
version='0.1')
1120+
"""))
1121+
script.pip('install', 'setuptools>24.2') # This should not be needed
1122+
script.pip('install', 'wheel')
1123+
script.run(
1124+
'python', 'setup.py', 'bdist_wheel', '--universal', cwd=pkga_path)
1125+
result = script.pip('install', './pkga/dist/pkga-0.1-py2.py3-none-any.whl',
1126+
expect_error=True)
1127+
assert ("pkga requires Python '<1.0' "
1128+
"but the running Python is ") in result.stderr
1129+
1130+
1131+
def test_install_compatible_python_requires(script):
1132+
script.scratch_path.join("pkga").mkdir()
1133+
pkga_path = script.scratch_path / 'pkga'
1134+
pkga_path.join("setup.py").write(textwrap.dedent("""
1135+
from setuptools import setup
1136+
setup(name='pkga',
1137+
python_requires='>1.0',
1138+
version='0.1')
1139+
"""))
1140+
script.pip('install', 'setuptools>24.2') # This should not be needed
1141+
res = script.pip('install', pkga_path, expect_error=True)
1142+
assert "Successfully installed pkga-0.1" in res.stdout, res

0 commit comments

Comments
 (0)