Merged in msabramo/pytest/color_option (pull request #90)

Add option: --color=(yes/no/auto)
This commit is contained in:
holger krekel 2013-12-08 20:19:37 +01:00
commit 9e03ea8215
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):
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: