Skip to content

Commit

Permalink
Skip progress display when in non-terminal (pytest >= 2.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 4, 2016
1 parent ba35a3d commit 5867a40
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
19 changes: 19 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,22 @@ def test_worker_id1(worker_id, run_num):
assert worker_ids == set(['master'])
else:
assert worker_ids == set(['gw0', 'gw1'])


def test_color_yes_collection_on_non_atty(testdir):
"""skip collect progress report when working on non-terminals.
Similar to pytest-dev/pytest#1397
"""
testdir.makepyfile("""
import pytest
@pytest.mark.parametrize('i', range(10))
def test_this(i):
assert 1
""")
args = ['--color=yes', '-n2']
result = testdir.runpytest(*args)
assert 'test session starts' in result.stdout.str()
assert '\x1b[1m' in result.stdout.str()
assert 'gw0 C / gw1 C' not in result.stdout.str()
assert 'gw0 [10] / gw1 [10]' in result.stdout.str()
26 changes: 26 additions & 0 deletions testing/test_dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,32 @@ class gw2:
# ])
dsession.pytest_xdist_rsyncstart(source="hello", gateways=[gw1, gw2])
linecomp.assert_contains_lines(["[X1,X2] rsyncing: hello", ])

def test_color_yes_collection_on_non_atty(self, testdir, request):
"""skip collect progress report when working on non-terminals.
(similar to #1397 in pytest's repository)
"""
testdir.makepyfile(test_foo="""
import pytest
@pytest.mark.parametrize('i', range(10))
def test_this(i):
assert 1
""")
testdir.makepyfile(test_bar="""
import pytest
@pytest.mark.parametrize('i', range(10))
def test_this(i):
assert 1
""")
args = ['--color=yes', '-n2']
result = testdir.runpytest(*args)
assert 'test session starts' in result.stdout.str()
assert '\x1b[1m' in result.stdout.str()
assert 'gw0 I / gw1 I' in result.stdout.str()
assert 'gw0 [20] / gw1 [20]' in result.stdout.str()
tr = request.config.pluginmanager.getplugin("terminalreporter")
if hasattr(tr, 'isatty'):
assert 'gw0 C / gw1 C' not in result.stdout.str()


def test_report_collection_diff_equal():
Expand Down
7 changes: 5 additions & 2 deletions xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,17 +722,20 @@ def __init__(self, config):
self.tr = config.pluginmanager.getplugin("terminalreporter")
self._status = {}
self._lastlen = 0
self._isatty = self.tr.hasmarkup
if hasattr(self.tr, 'isatty'):
self._isatty = self.tr.isatty

def write_line(self, msg):
self.tr.write_line(msg)

def ensure_show_status(self):
if not self.tr.hasmarkup:
if not self._isatty:
self.write_line(self.getstatus())

def setstatus(self, spec, status, show=True):
self._status[spec.id] = status
if show and self.tr.hasmarkup:
if show and self._isatty:
self.rewrite(self.getstatus())

def getstatus(self):
Expand Down

0 comments on commit 5867a40

Please sign in to comment.