2022-06-07 11:52:38 +02:00
|
|
|
import os
|
2021-07-24 12:12:19 +02:00
|
|
|
import sys
|
2018-07-06 10:47:56 +02:00
|
|
|
import textwrap
|
2022-06-07 11:52:38 +02:00
|
|
|
from pathlib import Path
|
2018-07-06 10:47:56 +02:00
|
|
|
|
2019-05-09 19:35:40 +02:00
|
|
|
import pytest
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
from tests.lib import PipTestEnvironment
|
|
|
|
|
2016-02-09 00:29:11 +01:00
|
|
|
|
2019-05-09 17:48:43 +02:00
|
|
|
@pytest.fixture
|
2021-09-13 00:31:12 +02:00
|
|
|
def warnings_demo(tmpdir: Path) -> Path:
|
2019-07-02 07:00:32 +02:00
|
|
|
demo = tmpdir.joinpath("warnings_demo.py")
|
|
|
|
demo.write_text(
|
|
|
|
textwrap.dedent(
|
2021-08-13 15:23:45 +02:00
|
|
|
"""
|
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
|
|
|
|
2021-07-29 00:51:18 +02:00
|
|
|
deprecation.deprecated(reason="deprecated!", replacement=None, gone_in=None)
|
2021-08-13 15:23:45 +02:00
|
|
|
"""
|
2018-07-06 10:47:56 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
)
|
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
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_deprecation_warnings_are_correct(
|
|
|
|
script: PipTestEnvironment, warnings_demo: Path
|
|
|
|
) -> None:
|
2022-06-07 11:52:38 +02:00
|
|
|
result = script.run("python", os.fspath(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
|
|
|
|
2019-05-09 17:49:06 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_deprecation_warnings_can_be_silenced(
|
|
|
|
script: PipTestEnvironment, warnings_demo: Path
|
|
|
|
) -> None:
|
2016-02-09 00:29:11 +01:00
|
|
|
script.environ["PYTHONWARNINGS"] = "ignore"
|
2022-06-07 11:52:38 +02:00
|
|
|
result = script.run("python", os.fspath(warnings_demo))
|
2016-02-09 00:29:11 +01:00
|
|
|
assert result.stderr == ""
|
2019-12-15 02:59:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
DEPRECATION_TEXT = "drop support for Python 2.7"
|
|
|
|
CPYTHON_DEPRECATION_TEXT = "January 1st, 2020"
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_version_warning_is_not_shown_if_python_version_is_not_2(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2019-12-15 02:59:34 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_flag_does_nothing_if_python_version_is_not_2(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2019-12-15 02:59:34 +01:00
|
|
|
script.pip("list", "--no-python-version-warning")
|
2021-04-05 16:31:08 +02:00
|
|
|
|
|
|
|
|
2021-07-24 12:12:19 +02:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
sys.version_info >= (3, 10), reason="distutils is deprecated in 3.10+"
|
|
|
|
)
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_pip_works_with_warnings_as_errors(script: PipTestEnvironment) -> None:
|
2021-04-05 16:31:08 +02:00
|
|
|
script.environ["PYTHONWARNINGS"] = "error"
|
|
|
|
script.pip("--version")
|