Skip to content

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

Merged
merged 1 commit into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,45 @@
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED


import argparse


class MoreQuietAction(argparse.Action):
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member Author

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 ^^

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

"""
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm do we really need to deprecate namespace.quiet? If all we need to do is to keep this line around, I wouldn't bother TBH.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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, "
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions changelog/3296.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New ``--verbosity`` flag to set verbosity level explicitly.
1 change: 1 addition & 0 deletions changelog/3296.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactoring to unify how verbosity is handled internally.