introduce "-q" option which decreases verbosity and basically leads to a unittest/nosetest-style "." output

add it in an ini file like this:

    [pytest]
    addargs=-q

and you get that by default.
This commit is contained in:
holger krekel 2010-10-31 19:51:16 +01:00
parent bb50ec89a9
commit 8871ca5bfa
5 changed files with 36 additions and 9 deletions

View File

@ -2,7 +2,7 @@
import cProfile
import py
import pstats
stats = cProfile.run('py.test.cmdline.main(["empty.py"])', 'prof')
stats = cProfile.run('py.test.cmdline.main(["empty.py", ])', 'prof')
p = pstats.Stats("prof")
p.strip_dirs()
p.sort_stats('cumulative')

View File

@ -23,7 +23,7 @@ You can create a simple example file:
and if you installed `PyYAML`_ or a compatible YAML-parser you can
now execute the test specification::
nonpython $ py.test
nonpython $ py.test test_simple.yml
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev10
test path 1: /home/hpk/p/pytest/doc/example/nonpython

View File

@ -11,6 +11,8 @@ def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "reporting", after="general")
group._addoption('-v', '--verbose', action="count",
dest="verbose", default=0, help="increase verbosity."),
group._addoption('-q', '--quiet', action="count",
dest="quiet", default=0, help="decreate verbosity."),
group._addoption('-r',
action="store", dest="reportchars", default=None, metavar="chars",
help="show extra test summary info as specified by chars (f)ailed, "
@ -30,6 +32,7 @@ def pytest_addoption(parser):
help="don't cut any tracebacks (default is to cut).")
def pytest_configure(config):
config.option.verbose -= config.option.quiet
if config.option.collectonly:
reporter = CollectonlyReporter(config)
else:
@ -87,6 +90,11 @@ def pytest_report_teststatus(report):
class TerminalReporter:
def __init__(self, config, file=None):
self.config = config
self.verbosity = self.config.option.verbose
self.showheader = self.verbosity >= 0
self.showfspath = self.verbosity >= 0
self.showlongtestinfo = self.verbosity > 0
self.stats = {}
self.curdir = py.path.local()
if file is None:
@ -158,10 +166,10 @@ class TerminalReporter:
def pytest_runtest_logstart(self, nodeid, location, fspath):
# ensure that the path is printed before the
# 1st test of a module starts running
if self.config.option.verbose:
if self.showlongtestinfo:
line = self._locationline(fspath, *location)
self.write_ensure_prefix(line, "")
else:
elif self.showfspath:
self.write_fspath_result(py.path.local(fspath), "")
def pytest_runtest_logreport(self, report):
@ -172,8 +180,8 @@ class TerminalReporter:
if not letter and not word:
# probably passed setup/teardown
return
if not self.config.option.verbose:
if not hasattr(rep, 'node'):
if self.verbosity <= 0:
if not hasattr(rep, 'node') and self.showfspath:
self.write_fspath_result(rep.fspath, letter)
else:
self._tw.write(letter)
@ -209,12 +217,14 @@ class TerminalReporter:
self.write_fspath_result(report.fspath, "S")
def pytest_sessionstart(self, session):
self.write_sep("=", "test session starts", bold=True)
self._sessionstarttime = py.std.time.time()
if not self.showheader:
return
self.write_sep("=", "test session starts", bold=True)
verinfo = ".".join(map(str, sys.version_info[:3]))
msg = "platform %s -- Python %s" % (sys.platform, verinfo)
msg += " -- pytest-%s" % (py.test.__version__)
if self.config.option.verbose or self.config.option.debug or \
if self.verbosity > 0 or self.config.option.debug or \
getattr(self.config.option, 'pastebin', None):
msg += " -- " + str(sys.executable)
self.write_line(msg)
@ -224,6 +234,8 @@ class TerminalReporter:
self.write_line(line)
def pytest_log_finishcollection(self):
if not self.showheader:
return
for i, testarg in enumerate(self.config.args):
self.write_line("test path %d: %s" %(i+1, testarg))
@ -333,7 +345,11 @@ class TerminalReporter:
parts.append("%d %s" %(len(val), key))
line = ", ".join(parts)
# XXX coloring
self.write_sep("=", "%s in %.2f seconds" %(line, session_duration), bold=True)
msg = "%s in %.2f seconds" %(line, session_duration)
if self.verbosity >= 0:
self.write_sep("=", msg, bold=True)
else:
self.write_line(msg, bold=True)
def summary_deselected(self):
if 'deselected' in self.stats:

View File

@ -37,6 +37,8 @@ def pytest_generate_tests(metafunc):
funcargs={'option': Option(verbose=False)})
metafunc.addcall(id="verbose",
funcargs={'option': Option(verbose=True)})
metafunc.addcall(id="quiet",
funcargs={'option': Option(verbose=-1)})
metafunc.addcall(id="fulltrace",
funcargs={'option': Option(fulltrace=True)})
@ -430,6 +432,14 @@ class TestTerminalFunctional:
])
assert result.ret == 1
def test_quiet_reporting(self, testdir):
p1 = testdir.makepyfile("def test_pass(): pass")
result = testdir.runpytest(p1, '-q')
s = result.stdout.str()
assert 'test session starts' not in s
assert p1.basename not in s
assert "===" not in s
def test_fail_extra_reporting(testdir):
p = testdir.makepyfile("def test_this(): assert 0")
result = testdir.runpytest(p)

View File

@ -52,3 +52,4 @@ commands=
[pytest]
minversion=2.0
plugins=pytester
#addargs=-q -x