summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2015-03-22 13:54:43 -0700
committerDamian Johnson <atagar@torproject.org>2015-03-22 13:54:43 -0700
commit40f87950078a1e167c454ecb52a4754c948d68df (patch)
treef2b2e57faa8e774da481232fa22e9491c5d4ae15
parent6d4d4816ff5cea7611bde36256d1f1b5e9eab5e9 (diff)
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
-rwxr-xr-xrun_tests.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/run_tests.py b/run_tests.py
index 7ae495e6..e4478669 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()