Add option: --color=(yes/no/auto)

--HG--
branch : color_option
This commit is contained in:
Marc Abramowitz 2013-12-06 11:49:48 -08:00
parent 98c6ced46e
commit 23fa4cec61
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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: