summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPradyun Gedam <pradyunsg@users.noreply.github.com>2021-07-29 10:44:55 +0100
committerPradyun Gedam <pradyunsg@users.noreply.github.com>2021-08-15 19:15:53 +0100
commit10c0f0d63783bbd8f988d471d9aa763451f97021 (patch)
treee24493d81ebcadeab31cbeb42a02a7d63c38d288
parent7bbbaa3857ea8d6a9bd7e30f7395b532d21612ad (diff)
downloadpip-10c0f0d63783bbd8f988d471d9aa763451f97021.tar.gz
Hide feature flag if deprecated behaviour is gone
-rw-r--r--src/pip/_internal/utils/deprecation.py6
-rw-r--r--tests/unit/test_utils.py31
2 files changed, 32 insertions, 5 deletions
diff --git a/src/pip/_internal/utils/deprecation.py b/src/pip/_internal/utils/deprecation.py
index a9df8296a..72bd6f25a 100644
--- a/src/pip/_internal/utils/deprecation.py
+++ b/src/pip/_internal/utils/deprecation.py
@@ -97,7 +97,9 @@ def deprecated(
),
(
feature_flag,
- "You can use the flag --use-feature={} to test the upcoming behaviour.",
+ "You can use the flag --use-feature={} to test the upcoming behaviour."
+ if not is_gone
+ else None,
),
(
issue,
@@ -108,7 +110,7 @@ def deprecated(
message = " ".join(
format_str.format(value)
for value, format_str in message_parts
- if value is not None
+ if format_str is not None and value is not None
)
# Raise as an error if this behaviour is deprecated.
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 3a031296d..c9228bc02 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -920,20 +920,22 @@ def test_deprecated_raises_error_if_too_old(replacement, issue, feature_flag):
assert "DEPRECATION: Stop doing this!" in message
assert "1.0" in message
+ assert str(feature_flag) not in message
# Ensure non-None values are mentioned.
- for item in [replacement, issue, feature_flag]:
+ for item in [replacement, issue]:
if item is not None:
assert str(item) in message
@pytest.mark.usefixtures("patch_deprecation_check_version")
-def test_deprecated_message_reads_well():
+def test_deprecated_message_reads_well_past():
with pytest.raises(PipDeprecationWarning) as exception:
deprecated(
reason="Stop doing this!",
gone_in="1.0", # this matches the patched version.
replacement="to be nicer",
- issue="100000", # I hope we never reach this number.
+ feature_flag="magic-8-ball",
+ issue="100000",
)
message = exception.value.args[0]
@@ -946,6 +948,29 @@ def test_deprecated_message_reads_well():
)
+@pytest.mark.usefixtures("patch_deprecation_check_version")
+def test_deprecated_message_reads_well_future():
+ with pytest.warns(PipDeprecationWarning) as record:
+ deprecated(
+ reason="Stop doing this!",
+ gone_in="2.0", # this is greater than the patched version.
+ replacement="to be nicer",
+ feature_flag="crisis",
+ issue="100000",
+ )
+
+ assert len(record) == 1
+ message = record[0].message.args[0]
+
+ assert message == (
+ "DEPRECATION: Stop doing this! "
+ "pip 2.0 will enforce this behaviour change. "
+ "A possible replacement is to be nicer. "
+ "You can use the flag --use-feature=crisis to test the upcoming behaviour. "
+ "Discussion can be found at https://github.com/pypa/pip/issues/100000"
+ )
+
+
def test_make_setuptools_shim_args():
# Test all arguments at once, including the overall ordering.
args = make_setuptools_shim_args(