[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Provide stacktrace when test encounter a syntax error



commit 40f87950078a1e167c454ecb52a4754c948d68df
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 22 13:54:43 2015 -0700

    Provide stacktrace when test encounter a syntax error
    
    Sebastian spotted that we swallow exceptions when loadTestsFromName() fails,
    often due to syntax errors and the like. Revising his improvements around
    this...
    
    * We added a traceback import but didn't actually use it.
    
    * PEP8 nitpick about import order. Imports are grouped by type (standard libs
      then stem imports), and within that alphabetical.
    
    * This added extra output for when the user gives '--test' for something that
      doesn't exist. We probably already have good enough output around this.
    
    * Calling exceptions 'exc' rather than 'e'. Nitpick of mine, but single letter
      variables are ungrepable so I only use them for a few specific things like
      list comprehension.
    
    * Inverted order in which we print so we still show 'failed' in the column,
      then are followed by the stacktrace.
    
    Errors previously looked like...
    
      version...                                          invalid syntax (version.py, line 30)
    
     failed
    
    ... and now look like...
    
      version...                                           failed
    Traceback (most recent call last):
      File "./run_tests.py", line 342, in _run_test
        suite = unittest.TestLoader().loadTestsFromName(test_class)
      File "/usr/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
        module = __import__('.'.join(parts_copy))
      File "/home/atagar/Desktop/stem/test/unit/version.py", line 30
        blargy blarg, some invalid python stuff... I hope
                   ^
    SyntaxError: invalid syntax
---
 run_tests.py |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 7ae495e..e447866 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -10,8 +10,8 @@ import os
 import sys
 import threading
 import time
-import unittest
 import traceback
+import unittest
 
 try:
   from StringIO import StringIO
@@ -340,14 +340,13 @@ def _run_test(args, test_class, output_filters, logging_buffer):
 
   try:
     suite = unittest.TestLoader().loadTestsFromName(test_class)
-  except AttributeError as e:
+  except AttributeError:
     # should only come up if user provided '--test' for something that doesn't exist
-    println("%s\n" % e, ERROR)
     println(" no such test", ERROR)
     return None
-  except Exception as e:
-    println("%s\n" % e, ERROR)
+  except Exception as exc:
     println(" failed", ERROR)
+    traceback.print_exc(exc)
     return None
 
   test_results = StringIO()



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits