Skip progress display when in non-terminal (pytest >= 2.9)
See pytest-dev/pytest#1397
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
- new ``worker_id`` fixture, returns the id of the worker in a test or fixture.
|
- new ``worker_id`` fixture, returns the id of the worker in a test or fixture.
|
||||||
Thanks Jared Hellman for the PR.
|
Thanks Jared Hellman for the PR.
|
||||||
|
|
||||||
|
- display progress during collection only when in a terminal, similar to pytest #1397 issue.
|
||||||
|
Thanks Bruno Oliveira for the PR.
|
||||||
|
|
||||||
|
|
||||||
1.14
|
1.14
|
||||||
----
|
----
|
||||||
|
|||||||
@@ -642,3 +642,25 @@ def test_worker_id_fixture(testdir, n):
|
|||||||
assert worker_ids == set(['master'])
|
assert worker_ids == set(['master'])
|
||||||
else:
|
else:
|
||||||
assert worker_ids == set(['gw0', 'gw1'])
|
assert worker_ids == set(['gw0', 'gw1'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_color_yes_collection_on_non_atty(testdir, request):
|
||||||
|
"""skip collect progress report when working on non-terminals.
|
||||||
|
|
||||||
|
Similar to pytest-dev/pytest#1397
|
||||||
|
"""
|
||||||
|
tr = request.config.pluginmanager.getplugin("terminalreporter")
|
||||||
|
if not hasattr(tr, 'isatty'):
|
||||||
|
pytest.skip('only valid for newer pytest versions')
|
||||||
|
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 [10] / gw1 [10]' in result.stdout.str()
|
||||||
|
assert 'gw0 C / gw1 C' not in result.stdout.str()
|
||||||
|
|||||||
@@ -722,17 +722,18 @@ class TerminalDistReporter:
|
|||||||
self.tr = config.pluginmanager.getplugin("terminalreporter")
|
self.tr = config.pluginmanager.getplugin("terminalreporter")
|
||||||
self._status = {}
|
self._status = {}
|
||||||
self._lastlen = 0
|
self._lastlen = 0
|
||||||
|
self._isatty = getattr(self.tr, 'isatty', self.tr.hasmarkup)
|
||||||
|
|
||||||
def write_line(self, msg):
|
def write_line(self, msg):
|
||||||
self.tr.write_line(msg)
|
self.tr.write_line(msg)
|
||||||
|
|
||||||
def ensure_show_status(self):
|
def ensure_show_status(self):
|
||||||
if not self.tr.hasmarkup:
|
if not self._isatty:
|
||||||
self.write_line(self.getstatus())
|
self.write_line(self.getstatus())
|
||||||
|
|
||||||
def setstatus(self, spec, status, show=True):
|
def setstatus(self, spec, status, show=True):
|
||||||
self._status[spec.id] = status
|
self._status[spec.id] = status
|
||||||
if show and self.tr.hasmarkup:
|
if show and self._isatty:
|
||||||
self.rewrite(self.getstatus())
|
self.rewrite(self.getstatus())
|
||||||
|
|
||||||
def getstatus(self):
|
def getstatus(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user