pip/tests/functional/test_warning.py

70 lines
2.2 KiB
Python
Raw Normal View History

import platform
2018-07-06 10:47:56 +02:00
import textwrap
2019-05-09 19:35:40 +02:00
import pytest
from tests.lib import skip_if_not_python2, skip_if_python2
2016-02-09 00:29:11 +01:00
2019-05-09 17:48:43 +02:00
@pytest.fixture
def warnings_demo(tmpdir):
demo = tmpdir.joinpath('warnings_demo.py')
demo.write_text(textwrap.dedent('''
2018-07-06 10:47:56 +02:00
from logging import basicConfig
from pip._internal.utils import deprecation
2016-02-09 00:29:11 +01:00
2018-07-06 10:47:56 +02:00
deprecation.install_warning_logger()
basicConfig()
2016-02-09 00:29:11 +01:00
2018-07-06 10:47:56 +02:00
deprecation.deprecated("deprecated!", replacement=None, gone_in=None)
'''))
2019-05-09 17:48:43 +02:00
return demo
2016-02-09 00:29:11 +01:00
2019-05-09 17:48:43 +02:00
def test_deprecation_warnings_are_correct(script, warnings_demo):
result = script.run('python', warnings_demo, expect_stderr=True)
2018-07-06 10:47:56 +02:00
expected = 'WARNING:pip._internal.deprecations:DEPRECATION: deprecated!\n'
assert result.stderr == expected
2016-02-09 00:29:11 +01:00
def test_deprecation_warnings_can_be_silenced(script, warnings_demo):
2016-02-09 00:29:11 +01:00
script.environ['PYTHONWARNINGS'] = 'ignore'
2019-05-09 17:48:43 +02:00
result = script.run('python', warnings_demo)
2016-02-09 00:29:11 +01:00
assert result.stderr == ''
DEPRECATION_TEXT = "drop support for Python 2.7"
CPYTHON_DEPRECATION_TEXT = "January 1st, 2020"
@skip_if_python2
def test_version_warning_is_not_shown_if_python_version_is_not_2(script):
result = script.pip("debug", allow_stderr_warning=True)
assert DEPRECATION_TEXT not in result.stderr, str(result)
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)
@skip_if_python2
def test_flag_does_nothing_if_python_version_is_not_2(script):
script.pip("list", "--no-python-version-warning")
@skip_if_not_python2
def test_version_warning_is_shown_if_python_version_is_2(script):
result = script.pip("debug", allow_stderr_warning=True)
assert DEPRECATION_TEXT in result.stderr, str(result)
if platform.python_implementation() == 'CPython':
assert CPYTHON_DEPRECATION_TEXT in result.stderr, str(result)
else:
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)
@skip_if_not_python2
def test_version_warning_is_not_shown_when_flag_is_passed(script):
result = script.pip(
"debug", "--no-python-version-warning", allow_stderr_warning=True
)
assert DEPRECATION_TEXT not in result.stderr, str(result)
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)
assert "--no-python-version-warning" not in result.stderr