Skip progress display when in non-terminal (pytest >= 2.9)

See pytest-dev/pytest#1397
This commit is contained in:
Bruno Oliveira
2016-03-08 17:20:36 -03:00
parent 8954f0d63d
commit 20fe1f9874
3 changed files with 28 additions and 2 deletions

View File

@@ -642,3 +642,25 @@ def test_worker_id_fixture(testdir, n):
assert worker_ids == set(['master'])
else:
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()