Skip to content

Commit c1b14cf

Browse files
unify cli verbosity handling
based on #3294 (comment) we really shouldnt have N options we post mortem hack together to determine verbosity this change starts by unifying the data, we still need to handle deprecation/removal of config.quiet
1 parent d6ddeb3 commit c1b14cf

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

_pytest/3296.trivial

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unify cli verbosity handling

_pytest/terminal.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,38 @@
1919
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED
2020

2121

22+
import argparse
23+
24+
class MoreQuietAction(argparse.Action):
25+
def __init__(self,
26+
option_strings,
27+
dest,
28+
default=None,
29+
required=False,
30+
help=None):
31+
super(MoreQuietAction, self).__init__(
32+
option_strings=option_strings,
33+
dest=dest,
34+
nargs=0,
35+
default=default,
36+
required=required,
37+
help=help)
38+
39+
def __call__(self, parser, namespace, values, option_string=None):
40+
new_count = getattr(namespace, self.dest, 0) - 1
41+
setattr(namespace, self.dest, new_count)
42+
# todo Deprecate config.quiet
43+
namespace.quiet = getattr(namespace, 'quiet', 0) + 1
44+
45+
2246
def pytest_addoption(parser):
2347
group = parser.getgroup("terminal reporting", "reporting", after="general")
2448
group._addoption('-v', '--verbose', action="count",
25-
dest="verbose", default=0, help="increase verbosity."),
26-
group._addoption('-q', '--quiet', action="count",
27-
dest="quiet", default=0, help="decrease verbosity."),
49+
dest="verbose", help="increase verbosity."),
50+
group._addoption('-q', '--quiet', action=MoreQuietAction,
51+
dest="verbose", help="decrease verbosity."),
52+
group.addoption("--verbosity", dest='verbose', type=int,
53+
help="set verbosity")
2854
group._addoption('-r',
2955
action="store", dest="reportchars", default='', metavar="chars",
3056
help="show extra test summary info as specified by chars (f)ailed, "
@@ -61,7 +87,6 @@ def pytest_addoption(parser):
6187

6288

6389
def pytest_configure(config):
64-
config.option.verbose -= config.option.quiet
6590
reporter = TerminalReporter(config, sys.stdout)
6691
config.pluginmanager.register(reporter, 'terminalreporter')
6792
if config.option.debug or config.option.traceconfig:

0 commit comments

Comments
 (0)