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..8fb01df36 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): + testdir.makepyfile("def test_this(): assert 1") + result = testdir.runpytest('--color=yes') + 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 'test session starts' in result.stdout.str() + assert u'\x1b[1m' not in result.stdout.str() + def test_getreportopt(): class config: class option: