-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
unify cli verbosity handling #3296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,45 @@ | |
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED | ||
|
||
|
||
import argparse | ||
|
||
|
||
class MoreQuietAction(argparse.Action): | ||
""" | ||
a modified copy of the argparse count action which counts down and updates | ||
the legacy quiet attribute at the same time | ||
|
||
used to unify verbosity handling | ||
""" | ||
def __init__(self, | ||
option_strings, | ||
dest, | ||
default=None, | ||
required=False, | ||
help=None): | ||
super(MoreQuietAction, self).__init__( | ||
option_strings=option_strings, | ||
dest=dest, | ||
nargs=0, | ||
default=default, | ||
required=required, | ||
help=help) | ||
|
||
def __call__(self, parser, namespace, values, option_string=None): | ||
new_count = getattr(namespace, self.dest, 0) - 1 | ||
setattr(namespace, self.dest, new_count) | ||
# todo Deprecate config.quiet | ||
namespace.quiet = getattr(namespace, 'quiet', 0) + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm do we really need to deprecate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its random shitty data showing up in introspection on top of that its half-dead zombie data and partially incorrect, it should go away There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't we remove it now? Is it because it might be used by thirdparty plugins? |
||
|
||
|
||
def pytest_addoption(parser): | ||
group = parser.getgroup("terminal reporting", "reporting", after="general") | ||
group._addoption('-v', '--verbose', action="count", | ||
dest="verbose", default=0, help="increase verbosity.") | ||
group._addoption('-q', '--quiet', action="count", | ||
dest="quiet", default=0, help="decrease verbosity.") | ||
group._addoption('-v', '--verbose', action="count", default=0, | ||
dest="verbose", help="increase verbosity."), | ||
group._addoption('-q', '--quiet', action=MoreQuietAction, default=0, | ||
dest="verbose", help="decrease verbosity."), | ||
group._addoption("--verbosity", dest='verbose', type=int, default=0, | ||
help="set verbosity") | ||
group._addoption('-r', | ||
action="store", dest="reportchars", default='', metavar="chars", | ||
help="show extra test summary info as specified by chars (f)ailed, " | ||
|
@@ -61,7 +94,6 @@ def pytest_addoption(parser): | |
|
||
|
||
def pytest_configure(config): | ||
config.option.verbose -= config.option.quiet | ||
reporter = TerminalReporter(config, sys.stdout) | ||
config.pluginmanager.register(reporter, 'terminalreporter') | ||
if config.option.debug or config.option.traceconfig: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
New ``--verbosity`` flag to set verbosity level explicitly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactoring to unify how verbosity is handled internally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring documenting why this class exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need this class. What does it fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it implements a negative counter and backward compat hacking, it can be simplified later on but its necessary since argparse itself is kinda shitty ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah. It is needed to get rid of
config.option.verbose -= config.option.quiet
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup