Skip to content

Commit 1dccfa4

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 1dccfa4

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
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: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,39 @@
1919
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED
2020

2121

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

6289

6390
def pytest_configure(config):
64-
config.option.verbose -= config.option.quiet
6591
reporter = TerminalReporter(config, sys.stdout)
6692
config.pluginmanager.register(reporter, 'terminalreporter')
6793
if config.option.debug or config.option.traceconfig:

0 commit comments

Comments
 (0)