Skip to content

Commit 23146e7

Browse files
committed
Fix usages of "verbose" option
With `-qq` `bool(config.getoption("verbose"))` is True; it needs to be checked for `> 0`.
1 parent 15d6088 commit 23146e7

File tree

7 files changed

+24
-22
lines changed

7 files changed

+24
-22
lines changed

changelog/4975.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the interpretation of ``-qq`` option where it was being considered as ``-v`` instead.

doc/en/builtin.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
5555
Example::
5656
5757
def test_foo(pytestconfig):
58-
if pytestconfig.getoption("verbose"):
58+
if pytestconfig.getoption("verbose") > 0:
5959
...
6060
record_property
6161
Add an extra properties the calling test.

src/_pytest/assertion/util.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def isiterable(obj):
151151
elif type(left) == type(right) and (isdatacls(left) or isattrs(left)):
152152
type_fn = (isdatacls, isattrs)
153153
explanation = _compare_eq_cls(left, right, verbose, type_fn)
154-
elif verbose:
154+
elif verbose > 0:
155155
explanation = _compare_eq_verbose(left, right)
156156
if isiterable(left) and isiterable(right):
157157
expl = _compare_eq_iterable(left, right, verbose)
@@ -175,8 +175,8 @@ def isiterable(obj):
175175
return [summary] + explanation
176176

177177

178-
def _diff_text(left, right, verbose=False):
179-
"""Return the explanation for the diff between text or bytes
178+
def _diff_text(left, right, verbose=0):
179+
"""Return the explanation for the diff between text or bytes.
180180
181181
Unless --verbose is used this will skip leading and trailing
182182
characters which are identical to keep the diff minimal.
@@ -202,7 +202,7 @@ def escape_for_readable_diff(binary_text):
202202
left = escape_for_readable_diff(left)
203203
if isinstance(right, bytes):
204204
right = escape_for_readable_diff(right)
205-
if not verbose:
205+
if verbose < 1:
206206
i = 0 # just in case left or right has zero length
207207
for i in range(min(len(left), len(right))):
208208
if left[i] != right[i]:
@@ -250,7 +250,7 @@ def _compare_eq_verbose(left, right):
250250
return explanation
251251

252252

253-
def _compare_eq_iterable(left, right, verbose=False):
253+
def _compare_eq_iterable(left, right, verbose=0):
254254
if not verbose:
255255
return [u"Use -v to get the full diff"]
256256
# dynamic import to speedup pytest
@@ -273,7 +273,7 @@ def _compare_eq_iterable(left, right, verbose=False):
273273
return explanation
274274

275275

276-
def _compare_eq_sequence(left, right, verbose=False):
276+
def _compare_eq_sequence(left, right, verbose=0):
277277
explanation = []
278278
for i in range(min(len(left), len(right))):
279279
if left[i] != right[i]:
@@ -292,7 +292,7 @@ def _compare_eq_sequence(left, right, verbose=False):
292292
return explanation
293293

294294

295-
def _compare_eq_set(left, right, verbose=False):
295+
def _compare_eq_set(left, right, verbose=0):
296296
explanation = []
297297
diff_left = left - right
298298
diff_right = right - left
@@ -307,7 +307,7 @@ def _compare_eq_set(left, right, verbose=False):
307307
return explanation
308308

309309

310-
def _compare_eq_dict(left, right, verbose=False):
310+
def _compare_eq_dict(left, right, verbose=0):
311311
explanation = []
312312
common = set(left).intersection(set(right))
313313
same = {k: left[k] for k in common if left[k] == right[k]}
@@ -368,7 +368,7 @@ def _compare_eq_cls(left, right, verbose, type_fns):
368368
return explanation
369369

370370

371-
def _notin_text(term, text, verbose=False):
371+
def _notin_text(term, text, verbose=0):
372372
index = text.find(term)
373373
head = text[:index]
374374
tail = text[index + len(term) :]

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def cache(request):
340340

341341
def pytest_report_header(config):
342342
"""Display cachedir with --cache-show and if non-default."""
343-
if config.option.verbose or config.getini("cache_dir") != ".pytest_cache":
343+
if config.option.verbose > 0 or config.getini("cache_dir") != ".pytest_cache":
344344
cachedir = config.cache._cachedir
345345
# TODO: evaluate generating upward relative paths
346346
# starting with .., ../.. if sensible

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ def pytestconfig(request):
10651065
Example::
10661066
10671067
def test_foo(pytestconfig):
1068-
if pytestconfig.getoption("verbose"):
1068+
if pytestconfig.getoption("verbose") > 0:
10691069
...
10701070
10711071
"""

src/_pytest/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def __init__(self, config):
389389
self._config = config
390390

391391
# enable verbose output automatically if live logging is enabled
392-
if self._log_cli_enabled() and not config.getoption("verbose"):
392+
if self._log_cli_enabled() and config.getoption("verbose") < 1:
393393
config.option.verbose = 1
394394

395395
self.print_logs = get_option_ini(config, "log_print")

testing/test_terminal.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,24 @@
2525

2626

2727
class Option(object):
28-
def __init__(self, verbose=False, fulltrace=False):
29-
self.verbose = verbose
28+
def __init__(self, verbosity=0, fulltrace=False):
29+
self.verbosity = verbosity
3030
self.fulltrace = fulltrace
3131

3232
@property
3333
def args(self):
3434
values = []
35-
if self.verbose:
36-
values.append("-v")
35+
values.append("--verbosity=%d" % self.verbosity)
3736
if self.fulltrace:
3837
values.append("--fulltrace")
3938
return values
4039

4140

4241
@pytest.fixture(
4342
params=[
44-
Option(verbose=False),
45-
Option(verbose=True),
46-
Option(verbose=-1),
43+
Option(verbosity=0),
44+
Option(verbosity=1),
45+
Option(verbosity=-1),
4746
Option(fulltrace=True),
4847
],
4948
ids=["default", "verbose", "quiet", "fulltrace"],
@@ -87,16 +86,18 @@ def test_func():
8786
"""
8887
)
8988
result = testdir.runpytest(*option.args)
90-
if option.verbose:
89+
if option.verbosity > 0:
9190
result.stdout.fnmatch_lines(
9291
[
9392
"*test_pass_skip_fail.py::test_ok PASS*",
9493
"*test_pass_skip_fail.py::test_skip SKIP*",
9594
"*test_pass_skip_fail.py::test_func FAIL*",
9695
]
9796
)
98-
else:
97+
elif option.verbosity == 0:
9998
result.stdout.fnmatch_lines(["*test_pass_skip_fail.py .sF*"])
99+
else:
100+
result.stdout.fnmatch_lines([".sF*"])
100101
result.stdout.fnmatch_lines(
101102
[" def test_func():", "> assert 0", "E assert 0"]
102103
)

0 commit comments

Comments
 (0)