Fix usages of "verbose" option

With `-qq` `bool(config.getoption("verbose"))` is True; it needs to be
checked for `> 0`.
This commit is contained in:
Daniel Hahler
2019-03-22 07:45:43 +01:00
parent 15d608867d
commit 23146e7527
7 changed files with 24 additions and 22 deletions

View File

@@ -151,7 +151,7 @@ def assertrepr_compare(config, op, left, right):
elif type(left) == type(right) and (isdatacls(left) or isattrs(left)):
type_fn = (isdatacls, isattrs)
explanation = _compare_eq_cls(left, right, verbose, type_fn)
elif verbose:
elif verbose > 0:
explanation = _compare_eq_verbose(left, right)
if isiterable(left) and isiterable(right):
expl = _compare_eq_iterable(left, right, verbose)
@@ -175,8 +175,8 @@ def assertrepr_compare(config, op, left, right):
return [summary] + explanation
def _diff_text(left, right, verbose=False):
"""Return the explanation for the diff between text or bytes
def _diff_text(left, right, verbose=0):
"""Return the explanation for the diff between text or bytes.
Unless --verbose is used this will skip leading and trailing
characters which are identical to keep the diff minimal.
@@ -202,7 +202,7 @@ def _diff_text(left, right, verbose=False):
left = escape_for_readable_diff(left)
if isinstance(right, bytes):
right = escape_for_readable_diff(right)
if not verbose:
if verbose < 1:
i = 0 # just in case left or right has zero length
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
@@ -250,7 +250,7 @@ def _compare_eq_verbose(left, right):
return explanation
def _compare_eq_iterable(left, right, verbose=False):
def _compare_eq_iterable(left, right, verbose=0):
if not verbose:
return [u"Use -v to get the full diff"]
# dynamic import to speedup pytest
@@ -273,7 +273,7 @@ def _compare_eq_iterable(left, right, verbose=False):
return explanation
def _compare_eq_sequence(left, right, verbose=False):
def _compare_eq_sequence(left, right, verbose=0):
explanation = []
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
@@ -292,7 +292,7 @@ def _compare_eq_sequence(left, right, verbose=False):
return explanation
def _compare_eq_set(left, right, verbose=False):
def _compare_eq_set(left, right, verbose=0):
explanation = []
diff_left = left - right
diff_right = right - left
@@ -307,7 +307,7 @@ def _compare_eq_set(left, right, verbose=False):
return explanation
def _compare_eq_dict(left, right, verbose=False):
def _compare_eq_dict(left, right, verbose=0):
explanation = []
common = set(left).intersection(set(right))
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):
return explanation
def _notin_text(term, text, verbose=False):
def _notin_text(term, text, verbose=0):
index = text.find(term)
head = text[:index]
tail = text[index + len(term) :]

View File

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

View File

@@ -1065,7 +1065,7 @@ def pytestconfig(request):
Example::
def test_foo(pytestconfig):
if pytestconfig.getoption("verbose"):
if pytestconfig.getoption("verbose") > 0:
...
"""

View File

@@ -389,7 +389,7 @@ class LoggingPlugin(object):
self._config = config
# enable verbose output automatically if live logging is enabled
if self._log_cli_enabled() and not config.getoption("verbose"):
if self._log_cli_enabled() and config.getoption("verbose") < 1:
config.option.verbose = 1
self.print_logs = get_option_ini(config, "log_print")