Add deprecate_python fixture to easily deprecate python versions

pip usually emits a warning and tests have to be adapted
This commit is contained in:
Xavier Fernandez 2019-01-11 11:12:44 +01:00
parent a09913673f
commit 5e573df69c
6 changed files with 53 additions and 21 deletions

View File

@ -277,7 +277,7 @@ def with_wheel(virtualenv, wheel_install):
@pytest.fixture
def script(tmpdir, virtualenv):
def script(tmpdir, virtualenv, deprecated_python):
"""
Return a PipTestEnvironment which is unique to each test function and
will execute all commands inside of the unique virtual environment for this
@ -301,6 +301,9 @@ def script(tmpdir, virtualenv):
# PipTestEnvironment needs to capture and assert against temp
capture_temp=True,
assert_no_temp=True,
# Deprecated python versions produce an extra deprecation warning
pip_expect_stderr=deprecated_python,
)
@ -341,3 +344,9 @@ class InMemoryPip(object):
@pytest.fixture
def in_memory_pip():
return InMemoryPip()
@pytest.fixture
def deprecated_python():
"""Used to indicate wheither pip deprecated this python version"""
return False

View File

@ -283,10 +283,10 @@ def test_completion_path_after_option(script, data):
@pytest.mark.parametrize('flag', ['--bash', '--zsh', '--fish'])
def test_completion_uses_same_executable_name(script, flag):
expect_stderr = sys.version_info[:2] == (3, 3)
def test_completion_uses_same_executable_name(script, flag, deprecated_python):
executable_name = 'pip{}'.format(sys.version_info[0])
# Deprecated python versions produce an extra deprecation warning
result = script.run(
executable_name, 'completion', flag, expect_stderr=expect_stderr
executable_name, 'completion', flag, expect_stderr=deprecated_python,
)
assert executable_name in result.stdout

View File

@ -138,7 +138,7 @@ def test_freeze_editable_not_vcs(script, tmpdir):
@pytest.mark.git
def test_freeze_editable_git_with_no_remote(script, tmpdir):
def test_freeze_editable_git_with_no_remote(script, tmpdir, deprecated_python):
"""
Test an editable Git install with no remote url.
"""
@ -146,7 +146,8 @@ def test_freeze_editable_git_with_no_remote(script, tmpdir):
script.pip('install', '-e', pkg_path)
result = script.pip('freeze')
assert result.stderr == ''
if not deprecated_python:
assert result.stderr == ''
# We need to apply os.path.normcase() to the path since that is what
# the freeze code does.
@ -460,7 +461,8 @@ _freeze_req_opts = textwrap.dedent("""\
""")
def test_freeze_with_requirement_option_file_url_egg_not_installed(script):
def test_freeze_with_requirement_option_file_url_egg_not_installed(
script, deprecated_python):
"""
Test "freeze -r requirements.txt" with a local file URL whose egg name
is not installed.
@ -477,7 +479,10 @@ def test_freeze_with_requirement_option_file_url_egg_not_installed(script):
'Requirement file [requirements.txt] contains {}, but package '
"'Does.Not-Exist' is not installed\n"
).format(url)
assert result.stderr == expected_err
if deprecated_python:
assert expected_err in result.stderr
else:
assert expected_err == result.stderr
def test_freeze_with_requirement_option(script):

View File

@ -37,7 +37,8 @@ def test_pep518_uses_build_env(script, data, common_wheels, command, variant):
)
def test_pep518_build_env_uses_same_pip(script, data, pip_src, common_wheels):
def test_pep518_build_env_uses_same_pip(
script, data, pip_src, common_wheels, deprecated_python):
"""Ensure the subprocess call to pip for installing the
build dependencies is using the same version of pip.
"""
@ -47,6 +48,7 @@ def test_pep518_build_env_uses_same_pip(script, data, pip_src, common_wheels):
'python', pip_src / 'src/pip', 'install', '--no-index',
'-f', common_wheels, '-f', data.packages,
data.src.join("pep518-3.0"),
expect_stderr=deprecated_python,
)
@ -162,8 +164,8 @@ def test_pep518_forkbombs(script, data, common_wheels, command, package):
@pytest.mark.network
def test_pip_second_command_line_interface_works(script, pip_src, data,
common_wheels):
def test_pip_second_command_line_interface_works(
script, pip_src, data, common_wheels, deprecated_python):
"""
Check if ``pip<PYVERSION>`` commands behaves equally
"""
@ -171,7 +173,7 @@ def test_pip_second_command_line_interface_works(script, pip_src, data,
script.pip_install_local('-f', common_wheels, pip_src)
# On old versions of Python, urllib3/requests will raise a warning about
# the lack of an SSLContext.
kwargs = {}
kwargs = {'expect_stderr': deprecated_python}
if pyversion_tuple < (2, 7, 9):
kwargs['expect_stderr'] = True

View File

@ -1,11 +1,14 @@
from tests.lib import create_test_package_with_setup
def matches_expected_lines(string, expected_lines):
return set(string.splitlines()) == set(expected_lines)
def matches_expected_lines(string, expected_lines, exact=True):
if exact:
return set(string.splitlines()) == set(expected_lines)
# If not exact, check that all expected lines are present
return set(expected_lines) <= set(string.splitlines())
def test_check_install_canonicalization(script):
def test_check_install_canonicalization(script, deprecated_python):
pkga_path = create_test_package_with_setup(
script,
name='pkgA',
@ -33,7 +36,9 @@ def test_check_install_canonicalization(script):
expected_lines = [
"pkga 1.0 requires SPECIAL.missing, which is not installed.",
]
assert matches_expected_lines(result.stderr, expected_lines)
# Deprecated python versions produce an extra warning on stderr
assert matches_expected_lines(
result.stderr, expected_lines, exact=not deprecated_python)
assert result.returncode == 0
# Install the second missing package and expect that there is no warning
@ -42,7 +47,8 @@ def test_check_install_canonicalization(script):
result = script.pip(
'install', '--no-index', special_path, '--quiet',
)
assert matches_expected_lines(result.stderr, [])
assert matches_expected_lines(
result.stderr, [], exact=not deprecated_python)
assert result.returncode == 0
# Double check that all errors are resolved in the end
@ -54,7 +60,8 @@ def test_check_install_canonicalization(script):
assert result.returncode == 0
def test_check_install_does_not_warn_for_out_of_graph_issues(script):
def test_check_install_does_not_warn_for_out_of_graph_issues(
script, deprecated_python):
pkg_broken_path = create_test_package_with_setup(
script,
name='broken',
@ -74,7 +81,9 @@ def test_check_install_does_not_warn_for_out_of_graph_issues(script):
# Install a package without it's dependencies
result = script.pip('install', '--no-index', pkg_broken_path, '--no-deps')
assert matches_expected_lines(result.stderr, [])
# Deprecated python versions produce an extra warning on stderr
assert matches_expected_lines(
result.stderr, [], exact=not deprecated_python)
# Install conflict package
result = script.pip(
@ -86,14 +95,15 @@ def test_check_install_does_not_warn_for_out_of_graph_issues(script):
"broken 1.0 has requirement conflict<1.0, but "
"you'll have conflict 1.0 which is incompatible."
),
])
], exact=not deprecated_python)
# Install unrelated package
result = script.pip(
'install', '--no-index', pkg_unrelated_path, '--quiet',
)
# should not warn about broken's deps when installing unrelated package
assert matches_expected_lines(result.stderr, [])
assert matches_expected_lines(
result.stderr, [], exact=not deprecated_python)
result = script.pip('check', expect_error=True)
expected_lines = [

View File

@ -323,6 +323,10 @@ class PipTestEnvironment(TestFileEnvironment):
environ["PYTHONIOENCODING"] = "UTF-8"
kwargs["environ"] = environ
# Whether all pip invocations should expect stderr
# (useful for Python version deprecation)
self.pip_expect_stderr = kwargs.pop('pip_expect_stderr', None)
# Call the TestFileEnvironment __init__
super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)
@ -375,6 +379,8 @@ class PipTestEnvironment(TestFileEnvironment):
)
def pip(self, *args, **kwargs):
if self.pip_expect_stderr:
kwargs['expect_stderr'] = True
# On old versions of Python, urllib3/requests will raise a warning
# about the lack of an SSLContext. Expect it when running commands
# that will touch the outside world.