From 20fe1f987487b53e927fe8e86e427007b29096eb Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 8 Mar 2016 17:20:36 -0300 Subject: [PATCH 1/4] Skip progress display when in non-terminal (pytest >= 2.9) See pytest-dev/pytest#1397 --- CHANGELOG | 3 +++ testing/acceptance_test.py | 22 ++++++++++++++++++++++ xdist/dsession.py | 5 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1e212b6..29c5dd5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ - new ``worker_id`` fixture, returns the id of the worker in a test or fixture. 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 ---- diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 9ba158b..a736ad9 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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() diff --git a/xdist/dsession.py b/xdist/dsession.py index fa66f1d..ae71db4 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -722,17 +722,18 @@ class TerminalDistReporter: self.tr = config.pluginmanager.getplugin("terminalreporter") self._status = {} self._lastlen = 0 + self._isatty = getattr(self.tr, 'isatty', self.tr.hasmarkup) 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): From dd3d180fe3161f9a9a450a83d1b30c0186ecf7e1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 4 May 2016 17:34:45 -0300 Subject: [PATCH 2/4] Add pytest 2.9 and drop pytest 2.4 and 2.5 from build matrix --- .travis.yml | 10 ++++------ tox.ini | 9 ++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f7910e..6acf63a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,23 +8,21 @@ install: "pip install -U tox setuptools_scm" env: matrix: # note: please use "tox --listenvs" to populate the build matrix - - TESTENV=py26-pytest24 - - TESTENV=py26-pytest25 - TESTENV=py26-pytest26 - TESTENV=py26-pytest27 - TESTENV=py26-pytest28 - - TESTENV=py27-pytest24 - - TESTENV=py27-pytest25 + - TESTENV=py26-pytest29 - TESTENV=py27-pytest26 - TESTENV=py27-pytest27 - TESTENV=py27-pytest28 - - TESTENV=py34-pytest24 - - TESTENV=py34-pytest25 + - TESTENV=py27-pytest29 - TESTENV=py34-pytest26 - TESTENV=py34-pytest27 - TESTENV=py34-pytest28 + - TESTENV=py34-pytest29 - TESTENV=py35-pytest27 - TESTENV=py35-pytest28 + - TESTENV=py35-pytest29 - TESTENV=py27-pytest28-pexpect - TESTENV=py35-pytest28-pexpect - TESTENV=flakes diff --git a/tox.ini b/tox.ini index 54fb438..4e9273e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] # if you change the envlist, please update .travis.yml file as well envlist= - py{26,27,34}-pytest2{4,5,6,7,8} - py35-pytest2{7,8} + py{26,27,34}-pytest2{6,7,8,9} + py35-pytest2{7,8,9} py{27,35}-pytest28-pexpect flakes readme @@ -14,11 +14,10 @@ passenv = USER USERNAME deps = pycmd setuptools_scm # to avoid .eggs - pytest24: pytest~=2.4.0 - pytest25: pytest~=2.5.0 pytest26: pytest~=2.6.1 pytest27: pytest~=2.7.2 - pytest28: pytest~=2.8.3 + pytest28: pytest~=2.8.7 + pytest29: pytest~=2.9.1 pexpect: pexpect platform= pexpect: linux|darwin From 8ec8d29cbf4f01ef20b88c1cad48ec93ef0fc500 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 11 May 2016 22:25:12 -0300 Subject: [PATCH 3/4] Mark test_remoteinitconfig as xfail #59 --- testing/test_remote.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/test_remote.py b/testing/test_remote.py index 7bac373..8192b7d 100644 --- a/testing/test_remote.py +++ b/testing/test_remote.py @@ -1,4 +1,5 @@ import py +import pytest from xdist.slavemanage import SlaveController, unserialize_report from xdist.remote import serialize_report import execnet @@ -62,6 +63,7 @@ def pytest_funcarg__slave(request): return SlaveSetup(request) +@pytest.mark.xfail(reason='#59') def test_remoteinitconfig(testdir): from xdist.remote import remote_initconfig config1 = testdir.parseconfig() From 9786e3d7744f5312cf45d13f6471ff29ee11c571 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 11 May 2016 22:28:22 -0300 Subject: [PATCH 4/4] Move comment in tox.ini Latest tox seems to be broken in this regard, it is not stripping the comment from the dependency line --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 4e9273e..7095101 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,8 @@ changedir=testing passenv = USER USERNAME deps = pycmd - setuptools_scm # to avoid .eggs + # to avoid .eggs + setuptools_scm pytest26: pytest~=2.6.1 pytest27: pytest~=2.7.2 pytest28: pytest~=2.8.7