Skip to content

Commit

Permalink
Package installation output is now affected by verbosity (-vv)
Browse files Browse the repository at this point in the history
Solves issue tox-dev#353.

Add changelog and contributors entry

Add integration tests

expose _get_verbosity() in public api, improve docs and help messages
  • Loading branch information
rogalski committed Nov 6, 2016
1 parent 8610a9a commit a4bc5fc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ unreleased
- fix #305: ``downloadcache`` test env config is now ignored as pip-8
does caching by default. Thanks holger krekel.

- output from install command in verbose (-vv) mode is now printed to console instead of
being redirected to file, thanks Lukasz Rogalski

2.4.1
-----

Expand Down
16 changes: 16 additions & 0 deletions tests/test_z_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,22 @@ def test_envsitepackagesdir_skip_missing_issue280(cmd, initproj):
""")


@pytest.mark.parametrize('verbosity', ['', '-v', '-vv'])
def test_verbosity(cmd, initproj, verbosity):
initproj("pkgX-0.0.5", filedefs={
'tox.ini': """
[testenv]
"""})
result = cmd.run("tox", verbosity)
assert result.ret == 0

needle = "Successfully installed pkgX-0.0.5"
if verbosity == '-vv':
assert any(needle in line for line in result.outlines)
else:
assert all(needle not in line for line in result.outlines)


def verify_json_report_format(data, testenvs=True):
assert data["reportversion"] == "1"
assert data["toxversion"] == tox.__version__
Expand Down
3 changes: 3 additions & 0 deletions tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def clear(self):
def __getattr__(self, name):
if name[0] == "_":
raise AttributeError(name)
elif name == 'verbosity':
# FIXME: special case for property on Reporter class, may it be generalized?
return 0

def generic_report(*args, **kwargs):
self._calls.append((name,) + args)
Expand Down
3 changes: 2 additions & 1 deletion tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def tox_addoption(parser):
help="show help about ini-names")
parser.add_argument("-v", nargs=0, action=CountAction, default=0,
dest="verbosity",
help="increase verbosity of reporting output.")
help="increase verbosity of reporting output. -vv mode turns off "
"output redirection for package installation")
parser.add_argument("--showconfig", action="store_true",
help="show configuration information for all environments. ")
parser.add_argument("-l", "--listenvs", action="store_true",
Expand Down
13 changes: 7 additions & 6 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def __init__(self, session):
self._reportedlines = []
# self.cumulated_time = 0.0

def _get_verbosity(self):
@property
def verbosity(self):
if self.session:
return self.session.config.option.verbosity
else:
Expand Down Expand Up @@ -268,11 +269,11 @@ def startsummary(self):
self.tw.sep("_", "summary")

def info(self, msg):
if self._get_verbosity() >= 2:
if self.verbosity >= 2:
self.logline(msg)

def using(self, msg):
if self._get_verbosity() >= 1:
if self.verbosity >= 1:
self.logline("using %s" % (msg,), bold=True)

def keyboard_interrupt(self):
Expand Down Expand Up @@ -308,15 +309,15 @@ def logline(self, msg, **opts):
self.tw.line("%s" % msg, **opts)

def verbosity0(self, msg, **opts):
if self._get_verbosity() >= 0:
if self.verbosity >= 0:
self.logline("%s" % msg, **opts)

def verbosity1(self, msg, **opts):
if self._get_verbosity() >= 1:
if self.verbosity >= 1:
self.logline("%s" % msg, **opts)

def verbosity2(self, msg, **opts):
if self._get_verbosity() >= 2:
if self.verbosity >= 2:
self.logline("%s" % msg, **opts)

# def log(self, msg):
Expand Down
3 changes: 2 additions & 1 deletion tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ def run_install_command(self, packages, action, options=()):

old_stdout = sys.stdout
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action)
self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action,
redirect=self.session.report.verbosity < 2)
sys.stdout = old_stdout

def _install(self, deps, extraopts=None, action=None):
Expand Down

0 comments on commit a4bc5fc

Please sign in to comment.