Skip to content

Commit 519accf

Browse files
committed
Skip progress display when in non-terminal (pytest >= 2.9)
See pytest-dev/pytest#1397
1 parent ba35a3d commit 519accf

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
- new ``worker_id`` fixture, returns the id of the worker in a test or fixture.
55
Thanks Jared Hellman for the PR.
66

7+
- display progress during collection only when in a terminal, similar to pytest #1397 issue.
8+
Thanks Bruno Oliveira for the PR.
9+
710

811
1.14
912
----

testing/acceptance_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,22 @@ def test_worker_id1(worker_id, run_num):
642642
assert worker_ids == set(['master'])
643643
else:
644644
assert worker_ids == set(['gw0', 'gw1'])
645+
646+
647+
def test_color_yes_collection_on_non_atty(testdir):
648+
"""skip collect progress report when working on non-terminals.
649+
650+
Similar to pytest-dev/pytest#1397
651+
"""
652+
testdir.makepyfile("""
653+
import pytest
654+
@pytest.mark.parametrize('i', range(10))
655+
def test_this(i):
656+
assert 1
657+
""")
658+
args = ['--color=yes', '-n2']
659+
result = testdir.runpytest(*args)
660+
assert 'test session starts' in result.stdout.str()
661+
assert '\x1b[1m' in result.stdout.str()
662+
assert 'gw0 C / gw1 C' not in result.stdout.str()
663+
assert 'gw0 [10] / gw1 [10]' in result.stdout.str()

xdist/dsession.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,17 +722,20 @@ def __init__(self, config):
722722
self.tr = config.pluginmanager.getplugin("terminalreporter")
723723
self._status = {}
724724
self._lastlen = 0
725+
self._isatty = self.tr.hasmarkup
726+
if hasattr(self.tr, 'isatty'):
727+
self._isatty = self.tr.isatty
725728

726729
def write_line(self, msg):
727730
self.tr.write_line(msg)
728731

729732
def ensure_show_status(self):
730-
if not self.tr.hasmarkup:
733+
if not self._isatty:
731734
self.write_line(self.getstatus())
732735

733736
def setstatus(self, spec, status, show=True):
734737
self._status[spec.id] = status
735-
if show and self.tr.hasmarkup:
738+
if show and self._isatty:
736739
self.rewrite(self.getstatus())
737740

738741
def getstatus(self):

0 commit comments

Comments
 (0)