[tor-commits] [stem/master] Including the test type or target with errors

atagar at torproject.org atagar at torproject.org
Tue Jan 24 17:28:58 UTC 2012


commit bda94c4dffa97f9cc915cddb45d90aab51e8e5b5
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Jan 23 19:11:07 2012 -0800

    Including the test type or target with errors
    
    When we have a failed test run with numerous targets we know at the end that an
    error occured and what it is, but not what target it occured under. It's a pita
    to scroll back looking for a stacktrace so including this with the footer's
    error information.
---
 run_tests.py   |    2 ++
 test/output.py |   19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index e3a9bbf..9e9eb00 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -229,6 +229,7 @@ if __name__ == '__main__':
   
   if CONFIG["argument.unit"]:
     test.output.print_divider("UNIT TESTS", True)
+    error_tracker.set_category("UNIT TEST")
     
     for test_class in UNIT_TESTS:
       test.output.print_divider(test_class.__module__)
@@ -284,6 +285,7 @@ if __name__ == '__main__':
     
     for target in integ_run_targets:
       if target in skip_targets: continue
+      error_tracker.set_category(target)
       
       try:
         # converts the 'target.torrc' csv into a list of test.runner.Torrc enums
diff --git a/test/output.py b/test/output.py
index 5ba9ca4..76156b9 100644
--- a/test/output.py
+++ b/test/output.py
@@ -164,6 +164,22 @@ class ErrorTracker:
   
   def __init__(self):
     self._errors = []
+    self._category = None
+  
+  def set_category(self, category):
+    """
+    Optional label that will be presented with testing failures until another
+    category is specified. If set to None then no category labels are included.
+    
+    For tests with a lot of output this is intended to help narrow the haystack
+    in which the user needs to look for failures. In practice this is mostly
+    used to specify the integ target we're running under.
+    
+    Arguments:
+      category (str) - category to label errors as being under
+    """
+    
+    self._category = category
   
   def has_error_occured(self):
     return bool(self._errors)
@@ -171,6 +187,9 @@ class ErrorTracker:
   def get_filter(self):
     def _error_tracker(line_type, line_content):
       if line_type in (LineType.FAIL, LineType.ERROR):
+        if self._category:
+          line_content = "[%s] %s" % (self._category, line_content)
+        
         self._errors.append(line_content)
       
       return line_content





More information about the tor-commits mailing list