From be11d3e19526148716b49705369cf0d2eeaf31a8 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 10 Aug 2018 12:49:06 -0300 Subject: [PATCH] Improve warning messages when addoption is called with string as `type` Encountered the warning myself and to me the message was not clear about what should be done to fix the warning --- src/_pytest/config/argparsing.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py index 21d99b0ce..5a4e35b88 100644 --- a/src/_pytest/config/argparsing.py +++ b/src/_pytest/config/argparsing.py @@ -174,23 +174,23 @@ class Argument(object): if isinstance(typ, six.string_types): if typ == "choice": warnings.warn( - "type argument to addoption() is a string %r." - " For parsearg this is optional and when supplied" - " should be a type." + "`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, - stacklevel=3, + stacklevel=4, ) # argparse expects a type here take it from # the type of the first element attrs["type"] = type(attrs["choices"][0]) else: warnings.warn( - "type argument to addoption() is a string %r." - " For parsearg this should be a type." + "`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=3, + stacklevel=4, ) attrs["type"] = Argument._typ_map[typ] # used in test_parseopt -> test_parse_defaultgetter