Skip to content

Commit 9f4cf09

Browse files
sigmavirus24gaborbernat
authored andcommitted
Add a -q (quiet) option to tox (tox-dev#682)
* Add a -q (quiet) option to tox Sometimes the output of tox in addition to the output of the command(s) tox is running can be a overwhelming and confusing. Allowing users to silence tox's output is incredibly useful in focusing on the command(s)'s output. Resolves tox-dev#256 * Add a changelog item and add myself to contributors * Rephrase our changelog item and fixup change Use a class to contain named constants to replace all the magic numbers used in the reporter. Further, rename the parsed values from the command-line.
1 parent bbbf5e2 commit 9f4cf09

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Eugene Yunak
2020
Fernando L. Pereira
2121
Hazal Ozturk
2222
Henk-Jaap Wagenaar
23+
Ian Stapleton Cordasco
2324
Igor Duarte Cardoso
2425
Ionel Maries Cristian
2526
Itxaka Serrano

changelog/256.feature.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Add a ``-q`` option to progressively silence tox's output. For each time you specify ``-q`` to tox,
2+
the output provided by tox reduces. This option allows you to see only your command output without
3+
the default verbosity of what tox is doing. This also counter-acts usage of ``-v``. For example,
4+
running ``tox -v -q ...`` will provide you with the default verbosity. ``tox -vv -q`` is equivalent
5+
to ``tox -v``. By @sigmavirus24

tests/test_config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,11 +1550,21 @@ def test_notest(self, newconfig):
15501550

15511551
def test_verbosity(self, newconfig):
15521552
config = newconfig([], "")
1553-
assert config.option.verbosity == 0
1553+
assert config.option.verbose_level == 0
15541554
config = newconfig(["-v"], "")
1555-
assert config.option.verbosity == 1
1555+
assert config.option.verbose_level == 1
15561556
config = newconfig(["-vv"], "")
1557-
assert config.option.verbosity == 2
1557+
assert config.option.verbose_level == 2
1558+
1559+
@pytest.mark.parametrize('args, expected', [
1560+
([], 0),
1561+
(["-q"], 1),
1562+
(["-qq"], 2),
1563+
(["-qqq"], 3),
1564+
])
1565+
def test_quiet(self, args, expected, newconfig):
1566+
config = newconfig(args, "")
1567+
assert config.option.quiet_level == expected
15581568

15591569
def test_substitution_jenkins_default(self, tmpdir,
15601570
monkeypatch, newconfig):

tox/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,11 @@ def tox_addoption(parser):
355355
help="show help about options")
356356
parser.add_argument("--help-ini", "--hi", action="store_true", dest="helpini",
357357
help="show help about ini-names")
358-
parser.add_argument("-v", action='count', dest="verbosity", default=0,
358+
parser.add_argument("-v", action='count', dest="verbose_level", default=0,
359359
help="increase verbosity of reporting output. -vv mode turns off "
360360
"output redirection for package installation")
361+
parser.add_argument("-q", action="count", dest="quiet_level", default=0,
362+
help="progressively silence reporting output.")
361363
parser.add_argument("--showconfig", action="store_true",
362364
help="show configuration information for all environments. ")
363365
parser.add_argument("-l", "--listenvs", action="store_true",

tox/session.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ def _popen(self, args, cwd, stdout, stderr, env=None):
230230
stdout=stdout, stderr=stderr, env=env)
231231

232232

233+
class Verbosity(object):
234+
DEBUG = 2
235+
INFO = 1
236+
DEFAULT = 0
237+
QUIET = -1
238+
EXTRA_QUIET = -2
239+
240+
233241
class Reporter(object):
234242
actionchar = "-"
235243

@@ -241,9 +249,10 @@ def __init__(self, session):
241249
@property
242250
def verbosity(self):
243251
if self.session:
244-
return self.session.config.option.verbosity
252+
return (self.session.config.option.verbose_level -
253+
self.session.config.option.quiet_level)
245254
else:
246-
return 2
255+
return Verbosity.DEBUG
247256

248257
def logpopen(self, popen, env):
249258
""" log information about the action.popen() created process. """
@@ -266,10 +275,11 @@ def logaction_finish(self, action):
266275
delattr(action, '_starttime')
267276

268277
def startsummary(self):
269-
self.tw.sep("_", "summary")
278+
if self.verbosity >= Verbosity.QUIET:
279+
self.tw.sep("_", "summary")
270280

271281
def info(self, msg):
272-
if self.verbosity >= 2:
282+
if self.verbosity >= Verbosity.DEBUG:
273283
self.logline(msg)
274284

275285
def using(self, msg):
@@ -293,28 +303,31 @@ def good(self, msg):
293303
self.logline(msg, green=True)
294304

295305
def warning(self, msg):
296-
self.logline("WARNING:" + msg, red=True)
306+
if self.verbosity >= Verbosity.QUIET:
307+
self.logline("WARNING:" + msg, red=True)
297308

298309
def error(self, msg):
299-
self.logline("ERROR: " + msg, red=True)
310+
if self.verbosity >= Verbosity.QUIET:
311+
self.logline("ERROR: " + msg, red=True)
300312

301313
def skip(self, msg):
302-
self.logline("SKIPPED:" + msg, yellow=True)
314+
if self.verbosity >= Verbosity.QUIET:
315+
self.logline("SKIPPED:" + msg, yellow=True)
303316

304317
def logline(self, msg, **opts):
305318
self._reportedlines.append(msg)
306319
self.tw.line("%s" % msg, **opts)
307320

308321
def verbosity0(self, msg, **opts):
309-
if self.verbosity >= 0:
322+
if self.verbosity >= Verbosity.DEFAULT:
310323
self.logline("%s" % msg, **opts)
311324

312325
def verbosity1(self, msg, **opts):
313-
if self.verbosity >= 1:
326+
if self.verbosity >= Verbosity.INFO:
314327
self.logline("%s" % msg, **opts)
315328

316329
def verbosity2(self, msg, **opts):
317-
if self.verbosity >= 2:
330+
if self.verbosity >= Verbosity.DEBUG:
318331
self.logline("%s" % msg, **opts)
319332

320333
# def log(self, msg):
@@ -378,12 +391,13 @@ def newaction(self, venv, msg, *args):
378391

379392
def runcommand(self):
380393
self.report.using("tox-%s from %s" % (tox.__version__, tox.__file__))
394+
verbosity = (self.report.verbosity > Verbosity.DEFAULT)
381395
if self.config.option.showconfig:
382396
self.showconfig()
383397
elif self.config.option.listenvs:
384-
self.showenvs(all_envs=False, description=self.config.option.verbosity > 0)
398+
self.showenvs(all_envs=False, description=verbosity)
385399
elif self.config.option.listenvs_all:
386-
self.showenvs(all_envs=True, description=self.config.option.verbosity > 0)
400+
self.showenvs(all_envs=True, description=verbosity)
387401
else:
388402
return self.subcommand_test()
389403

0 commit comments

Comments
 (0)