Skip to content
Snippets Groups Projects
Commit 40f87950 authored by Damian Johnson's avatar Damian Johnson
Browse files

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
parent 6d4d4816
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment