summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2021-02-04 11:52:13 +0200
committerRan Benita <ran@unusedvar.com>2021-02-05 00:05:47 +0200
commitd358a060add416e11b0e231cbfe9d97b02335ad0 (patch)
tree2eee4a26ede166584abd8e0427fa654c31862614 /src
parent3907856cb3748c3210e796f199c0625046d20896 (diff)
downloadpytest-d358a060add416e11b0e231cbfe9d97b02335ad0.tar.gz
config/argparsing: use proper deprecations instead of ad-hoc DeprecationWarning
Proper for removing this in the next major pytest release.
Diffstat (limited to 'src')
-rw-r--r--src/_pytest/config/argparsing.py22
-rw-r--r--src/_pytest/deprecated.py19
2 files changed, 25 insertions, 16 deletions
diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py
index 5a09ea781..cf738cc2b 100644
--- a/src/_pytest/config/argparsing.py
+++ b/src/_pytest/config/argparsing.py
@@ -18,6 +18,9 @@ from typing import Union
import _pytest._io
from _pytest.compat import final
from _pytest.config.exceptions import UsageError
+from _pytest.deprecated import ARGUMENT_PERCENT_DEFAULT
+from _pytest.deprecated import ARGUMENT_TYPE_STR
+from _pytest.deprecated import ARGUMENT_TYPE_STR_CHOICE
if TYPE_CHECKING:
from typing import NoReturn
@@ -212,12 +215,7 @@ class Argument:
self._short_opts: List[str] = []
self._long_opts: List[str] = []
if "%default" in (attrs.get("help") or ""):
- warnings.warn(
- 'pytest now uses argparse. "%default" should be'
- ' changed to "%(default)s" ',
- DeprecationWarning,
- stacklevel=3,
- )
+ warnings.warn(ARGUMENT_PERCENT_DEFAULT, stacklevel=3)
try:
typ = attrs["type"]
except KeyError:
@@ -227,11 +225,7 @@ class Argument:
if isinstance(typ, str):
if typ == "choice":
warnings.warn(
- "`type` argument to addoption() is the string %r."
- " For choices this is optional and can be omitted, "
- " but when supplied should be a type (for example `str` or `int`)."
- " (options: %s)" % (typ, names),
- DeprecationWarning,
+ ARGUMENT_TYPE_STR_CHOICE.format(typ=typ, names=names),
stacklevel=4,
)
# argparse expects a type here take it from
@@ -239,11 +233,7 @@ class Argument:
attrs["type"] = type(attrs["choices"][0])
else:
warnings.warn(
- "`type` argument to addoption() is the string %r, "
- " but when supplied should be a type (for example `str` or `int`)."
- " (options: %s)" % (typ, names),
- DeprecationWarning,
- stacklevel=4,
+ ARGUMENT_TYPE_STR.format(typ=typ, names=names), stacklevel=4
)
attrs["type"] = Argument._typ_map[typ]
# Used in test_parseopt -> test_parse_defaultgetter.
diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py
index fa91f9097..5efc004ac 100644
--- a/src/_pytest/deprecated.py
+++ b/src/_pytest/deprecated.py
@@ -69,6 +69,25 @@ UNITTEST_SKIP_DURING_COLLECTION = PytestDeprecationWarning(
"Use pytest.skip() instead."
)
+ARGUMENT_PERCENT_DEFAULT = PytestDeprecationWarning(
+ 'pytest now uses argparse. "%default" should be changed to "%(default)s"',
+)
+
+ARGUMENT_TYPE_STR_CHOICE = UnformattedWarning(
+ PytestDeprecationWarning,
+ "`type` argument to addoption() is the string {typ!r}."
+ " For choices this is optional and can be omitted, "
+ " but when supplied should be a type (for example `str` or `int`)."
+ " (options: {names})",
+)
+
+ARGUMENT_TYPE_STR = UnformattedWarning(
+ PytestDeprecationWarning,
+ "`type` argument to addoption() is the string {typ!r}, "
+ " but when supplied should be a type (for example `str` or `int`)."
+ " (options: {names})",
+)
+
# You want to make some `__init__` or function "private".
#