[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/testrunner add --auto-color option

Benji York benji at zope.com
Mon Jul 16 03:59:19 EDT 2007


Log message for revision 78022:
  add --auto-color option
  

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner-colors.txt
  U   zope.testing/trunk/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner-colors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-colors.txt	2007-07-16 07:56:19 UTC (rev 78021)
+++ zope.testing/trunk/src/zope/testing/testrunner-colors.txt	2007-07-16 07:59:18 UTC (rev 78022)
@@ -238,7 +238,6 @@
       Tear down samplelayers.Layer1 in 0.000 seconds.
     False
 
-
     >>> sys.argv = 'test --layer 122 -c --no-color'.split()
     >>> testrunner.run(defaults)
     Running samplelayers.Layer122 tests:
@@ -252,6 +251,24 @@
       Tear down samplelayers.Layer1 in 0.000 seconds.
     False
 
+The --auto-color option will determine if stdout is a terminal, and only enable
+colorized output if so.  Of course, stdout is not a terminal here, so no color
+will be produced:
+
+    >>> sys.argv = 'test --layer 122 --auto-color'.split()
+    >>> testrunner.run(defaults)
+    Running samplelayers.Layer122 tests:
+      Set up samplelayers.Layer1 in 0.000 seconds.
+      Set up samplelayers.Layer12 in 0.000 seconds.
+      Set up samplelayers.Layer122 in 0.000 seconds.
+      Ran 34 tests with 0 failures and 0 errors in 0.007 seconds.
+    Tearing down left over layers:
+      Tear down samplelayers.Layer122 in 0.000 seconds.
+      Tear down samplelayers.Layer12 in 0.000 seconds.
+      Tear down samplelayers.Layer1 in 0.000 seconds.
+    False
+
+
 Clean up:
 
     >>> sys.stdout = real_stdout

Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2007-07-16 07:56:19 UTC (rev 78021)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2007-07-16 07:59:18 UTC (rev 78022)
@@ -1977,6 +1977,9 @@
 ######################################################################
 # Reporting
 
+def handle_auto_color(option, opt_str, value, parser):
+    parser.values.color = sys.stdout.isatty()
+
 reporting = optparse.OptionGroup(parser, "Reporting", """\
 Reporting options control basic aspects of test-runner output
 """)
@@ -2014,6 +2017,12 @@
 """)
 
 reporting.add_option(
+    '--auto-color', action="callback", callback=handle_auto_color,
+    help="""\
+Colorize the output, but only when stdout is a terminal.
+""")
+
+reporting.add_option(
     '-1', '--hide-secondary-failures',
     action="store_true", dest='report_only_first_failure',
     help="""\



More information about the Zope3-Checkins mailing list