Commit a4f86aa2314561251c16650356b63e6306793fda

Authored by Christian Herdtweck
1 parent e310b9bb

unittest: Simplify running from command line

Unittests worked on Travis and from IDEs like PyCharm, but from
command line I had to change log helper test root dir to one level up
and unset PYTHONPATH
tests/util/log_helper/test_log_helper.py
... ... @@ -5,17 +5,20 @@ Check if it handles imported modules correctly
5 5 and that the default silent logger won't log when nothing is enabled
6 6 """
7 7  
  8 +from __future__ import print_function
  9 +
8 10 import unittest
9 11 import sys
10 12 import json
11 13 import re
12 14 from tests.util.log_helper import log_helper_test_main
13 15 from tests.util.log_helper import log_helper_test_imported
14   -from os.path import dirname, join
  16 +from os.path import dirname, join, relpath, abspath
15 17 from subprocess import check_output, STDOUT, CalledProcessError
16 18  
17   -ROOT_DIRECTORY = dirname(dirname(dirname(__file__)))
18   -TEST_FILE = join(dirname(__file__), 'log_helper_test_main.py')
  19 +# this is the common base of "tests" and "oletools" dirs
  20 +ROOT_DIRECTORY = dirname(dirname(dirname(dirname(abspath(__file__)))))
  21 +TEST_FILE = relpath(join(dirname(__file__), 'log_helper_test_main.py'), ROOT_DIRECTORY)
19 22 PYTHON_EXECUTABLE = sys.executable
20 23 REGEX = re.compile('<#(.*)(:?#>|Traceback)', re.MULTILINE | re.DOTALL)
21 24  
... ... @@ -146,6 +149,10 @@ class TestLogHelper(unittest.TestCase):
146 149 output = ex.output
147 150 else:
148 151 # we want tests to fail if an exception occur
  152 + print('Caught unexpected error. Print output and re-raise')
  153 + for line in ex.output.splitlines():
  154 + print('error output: {}'.format(line.rstrip()))
  155 + print('(If you have errors about imports, try unsetting PYTHONPATH)')
149 156 raise ex
150 157  
151 158 return REGEX.search(output).group(1).strip()
... ...