Skip to content

Commit

Permalink
Display collect progress only when in a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Feb 20, 2016
1 parent b76de91 commit a2fa70d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@

*

*
* Collection only displays progress ("collecting X items") when in a terminal.
This avoids cluttering the output when using ``--color=yes`` to obtain
colors in CI integrations systems (`#1397`_).

*

Expand Down Expand Up @@ -106,6 +108,7 @@
.. _#1226: https://github.com/pytest-dev/pytest/pull/1226
.. _#1290: https://github.com/pytest-dev/pytest/pull/1290
.. _#1355: https://github.com/pytest-dev/pytest/pull/1355
.. _#1397: https://github.com/pytest-dev/pytest/issues/1397
.. _@biern: https://github.com/biern
.. _@MichaelAquilina: https://github.com/MichaelAquilina
.. _@bukzor: https://github.com/bukzor
Expand Down
7 changes: 4 additions & 3 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(self, config, file=None):
self.currentfspath = None
self.reportchars = getreportopt(config)
self.hasmarkup = self._tw.hasmarkup
self.isatty = file.isatty()

def hasopt(self, char):
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
Expand Down Expand Up @@ -234,7 +235,7 @@ def pytest_runtest_logreport(self, report):
self.currentfspath = -2

def pytest_collection(self):
if not self.hasmarkup and self.config.option.verbose >= 1:
if not self.isatty and self.config.option.verbose >= 1:
self.write("collecting ... ", bold=True)

def pytest_collectreport(self, report):
Expand All @@ -244,7 +245,7 @@ def pytest_collectreport(self, report):
self.stats.setdefault("skipped", []).append(report)
items = [x for x in report.result if isinstance(x, pytest.Item)]
self._numcollected += len(items)
if self.hasmarkup:
if self.isatty:
#self.write_fspath_result(report.nodeid, 'E')
self.report_collect()

Expand All @@ -263,7 +264,7 @@ def report_collect(self, final=False):
line += " / %d errors" % errors
if skipped:
line += " / %d skipped" % skipped
if self.hasmarkup:
if self.isatty:
if final:
line += " \n"
self.rewrite(line, bold=True)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
build: false # Not a C# project, build stuff at the test step instead.

test_script:
- C:\Python35\python -m tox
- C:\Python35\python -m tox -- --color=yes
# coveralls is not in tox's envlist, plus for PRs the secure variable
# is not defined so we have to check for it
- if defined COVERALLS_REPO_TOKEN C:\Python35\python -m tox -e coveralls
25 changes: 25 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,37 @@ def test_color_yes(testdir):
assert 'test session starts' in result.stdout.str()
assert '\x1b[1m' in result.stdout.str()


def test_color_no(testdir):
testdir.makepyfile("def test_this(): assert 1")
result = testdir.runpytest('--color=no')
assert 'test session starts' in result.stdout.str()
assert '\x1b[1m' not in result.stdout.str()


@pytest.mark.parametrize('verbose', [True, False])
def test_color_yes_collection_on_non_atty(testdir, verbose):
"""skip collect progress report when working on non-terminals.
#1397
"""
testdir.makepyfile("""
import pytest
@pytest.mark.parametrize('i', range(10))
def test_this(i):
assert 1
""")
args = ['--color=yes']
if verbose:
args.append('-vv')
result = testdir.runpytest(*args)
assert 'test session starts' in result.stdout.str()
assert '\x1b[1m' in result.stdout.str()
assert 'collecting 10 items' not in result.stdout.str()
if verbose:
assert 'collecting ...' in result.stdout.str()
assert 'collected 10 items' in result.stdout.str()


def test_getreportopt():
class config:
class option:
Expand Down

0 comments on commit a2fa70d

Please sign in to comment.