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

@ -0,0 +1 @@
Fix the interpretation of ``-qq`` option where it was being considered as ``-v`` instead.

View File

@ -55,7 +55,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
Example:: Example::
def test_foo(pytestconfig): def test_foo(pytestconfig):
if pytestconfig.getoption("verbose"): if pytestconfig.getoption("verbose") > 0:
... ...
record_property record_property
Add an extra properties the calling test. Add an extra properties the calling test.

View File

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

View File

@ -340,7 +340,7 @@ def cache(request):
def pytest_report_header(config): def pytest_report_header(config):
"""Display cachedir with --cache-show and if non-default.""" """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 cachedir = config.cache._cachedir
# TODO: evaluate generating upward relative paths # TODO: evaluate generating upward relative paths
# starting with .., ../.. if sensible # starting with .., ../.. if sensible

View File

@ -1065,7 +1065,7 @@ def pytestconfig(request):
Example:: Example::
def test_foo(pytestconfig): 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 self._config = config
# enable verbose output automatically if live logging is enabled # 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 config.option.verbose = 1
self.print_logs = get_option_ini(config, "log_print") self.print_logs = get_option_ini(config, "log_print")

View File

@ -25,15 +25,14 @@ DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
class Option(object): class Option(object):
def __init__(self, verbose=False, fulltrace=False): def __init__(self, verbosity=0, fulltrace=False):
self.verbose = verbose self.verbosity = verbosity
self.fulltrace = fulltrace self.fulltrace = fulltrace
@property @property
def args(self): def args(self):
values = [] values = []
if self.verbose: values.append("--verbosity=%d" % self.verbosity)
values.append("-v")
if self.fulltrace: if self.fulltrace:
values.append("--fulltrace") values.append("--fulltrace")
return values return values
@ -41,9 +40,9 @@ class Option(object):
@pytest.fixture( @pytest.fixture(
params=[ params=[
Option(verbose=False), Option(verbosity=0),
Option(verbose=True), Option(verbosity=1),
Option(verbose=-1), Option(verbosity=-1),
Option(fulltrace=True), Option(fulltrace=True),
], ],
ids=["default", "verbose", "quiet", "fulltrace"], ids=["default", "verbose", "quiet", "fulltrace"],
@ -87,7 +86,7 @@ class TestTerminal(object):
""" """
) )
result = testdir.runpytest(*option.args) result = testdir.runpytest(*option.args)
if option.verbose: if option.verbosity > 0:
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"*test_pass_skip_fail.py::test_ok PASS*", "*test_pass_skip_fail.py::test_ok PASS*",
@ -95,8 +94,10 @@ class TestTerminal(object):
"*test_pass_skip_fail.py::test_func FAIL*", "*test_pass_skip_fail.py::test_func FAIL*",
] ]
) )
else: elif option.verbosity == 0:
result.stdout.fnmatch_lines(["*test_pass_skip_fail.py .sF*"]) result.stdout.fnmatch_lines(["*test_pass_skip_fail.py .sF*"])
else:
result.stdout.fnmatch_lines([".sF*"])
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[" def test_func():", "> assert 0", "E assert 0"] [" def test_func():", "> assert 0", "E assert 0"]
) )