From 23fa4cec610b12f494eb74218e48a68457bf0462 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 6 Dec 2013 11:49:48 -0800 Subject: [PATCH 1/3] Add option: --color=(yes/no/auto) --HG-- branch : color_option --- _pytest/terminal.py | 8 ++++++++ testing/test_terminal.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index aa2e90428..ade037432 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -29,6 +29,10 @@ def pytest_addoption(parser): group._addoption('--fulltrace', '--full-trace', action="store_true", default=False, help="don't cut any tracebacks (default is to cut).") + group._addoption('--color', metavar="color", + action="store", dest="color", default='auto', + choices=['yes', 'no', 'auto'], + help="color output (yes/no/auto).") def pytest_configure(config): config.option.verbose -= config.option.quiet @@ -85,6 +89,10 @@ class TerminalReporter: if file is None: file = py.std.sys.stdout self._tw = self.writer = py.io.TerminalWriter(file) + if self.config.option.color == 'yes': + self._tw.hasmarkup = True + if self.config.option.color == 'no': + self._tw.hasmarkup = False self.currentfspath = None self.reportchars = getreportopt(config) self.hasmarkup = self._tw.hasmarkup diff --git a/testing/test_terminal.py b/testing/test_terminal.py index c45703d5e..863b549e2 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1,6 +1,7 @@ """ terminal reporting of the full testing process. """ +import os import pytest, py import sys @@ -497,6 +498,18 @@ def test_fail_reporting_on_pass(testdir): result = testdir.runpytest('-rf') assert 'short test summary' not in result.stdout.str() +def test_color_yes(testdir, monkeypatch): + testdir.makepyfile("def test_this(): assert 1") + result = testdir.runpytest('--color=yes') + assert 'short test summary' not in result.stdout.str() + assert u'\x1b[1m' in result.stdout.str() + +def test_color_no(testdir): + testdir.makepyfile("def test_this(): assert 1") + result = testdir.runpytest('--color=no') + assert 'short test summary' not in result.stdout.str() + assert u'\x1b[1m' not in result.stdout.str() + def test_getreportopt(): class config: class option: From bec6ee5c29f0dd6aedf943629d71b323ea97440a Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 6 Dec 2013 11:58:04 -0800 Subject: [PATCH 2/3] Assert 'test session starts' in output for test_color_{yes,no} --HG-- branch : color_option --- testing/test_terminal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 863b549e2..a638d7d76 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -501,13 +501,13 @@ def test_fail_reporting_on_pass(testdir): def test_color_yes(testdir, monkeypatch): testdir.makepyfile("def test_this(): assert 1") result = testdir.runpytest('--color=yes') - assert 'short test summary' not in result.stdout.str() + assert 'test session starts' in result.stdout.str() assert u'\x1b[1m' in result.stdout.str() def test_color_no(testdir): testdir.makepyfile("def test_this(): assert 1") result = testdir.runpytest('--color=no') - assert 'short test summary' not in result.stdout.str() + assert 'test session starts' in result.stdout.str() assert u'\x1b[1m' not in result.stdout.str() def test_getreportopt(): From 60f5b15f2033939719a0dd39df3de2c779bd4206 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sat, 7 Dec 2013 12:04:23 -0800 Subject: [PATCH 3/3] Remove superfluous `monkeypatch` arg to test_color_yes --HG-- branch : color_option --- testing/test_terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index a638d7d76..8fb01df36 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -498,7 +498,7 @@ def test_fail_reporting_on_pass(testdir): result = testdir.runpytest('-rf') assert 'short test summary' not in result.stdout.str() -def test_color_yes(testdir, monkeypatch): +def test_color_yes(testdir): testdir.makepyfile("def test_this(): assert 1") result = testdir.runpytest('--color=yes') assert 'test session starts' in result.stdout.str()