Tests: added "-r" option to print unit.log on failures.
This commit is contained in:
@@ -30,6 +30,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
|
|
||||||
detailed = False
|
detailed = False
|
||||||
save_log = False
|
save_log = False
|
||||||
|
print_log = False
|
||||||
unsafe = False
|
unsafe = False
|
||||||
|
|
||||||
def __init__(self, methodName='runTest'):
|
def __init__(self, methodName='runTest'):
|
||||||
@@ -183,7 +184,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
shutil.rmtree(self.testdir)
|
shutil.rmtree(self.testdir)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._print_path_to_log()
|
self._print_log()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self._started:
|
if self._started:
|
||||||
@@ -281,14 +282,14 @@ class TestUnit(unittest.TestCase):
|
|||||||
alerts = [al for al in alerts if re.search(skip, al) is None]
|
alerts = [al for al in alerts if re.search(skip, al) is None]
|
||||||
|
|
||||||
if alerts:
|
if alerts:
|
||||||
self._print_path_to_log()
|
self._print_log(log)
|
||||||
self.assertFalse(alerts, 'alert(s)')
|
self.assertFalse(alerts, 'alert(s)')
|
||||||
|
|
||||||
if not self.skip_sanitizer:
|
if not self.skip_sanitizer:
|
||||||
sanitizer_errors = re.findall('.+Sanitizer.+', log)
|
sanitizer_errors = re.findall('.+Sanitizer.+', log)
|
||||||
|
|
||||||
if sanitizer_errors:
|
if sanitizer_errors:
|
||||||
self._print_path_to_log()
|
self._print_log(log)
|
||||||
self.assertFalse(sanitizer_errors, 'sanitizer error(s)')
|
self.assertFalse(sanitizer_errors, 'sanitizer error(s)')
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
@@ -360,6 +361,13 @@ class TestUnit(unittest.TestCase):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Save unit.log after the test execution',
|
help='Save unit.log after the test execution',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-r',
|
||||||
|
'--reprint_log',
|
||||||
|
dest='print_log',
|
||||||
|
action='store_true',
|
||||||
|
help='Print unit.log to stdout in case of errors',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-u',
|
'-u',
|
||||||
'--unsafe',
|
'--unsafe',
|
||||||
@@ -374,6 +382,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
def _set_args(args):
|
def _set_args(args):
|
||||||
TestUnit.detailed = args.detailed
|
TestUnit.detailed = args.detailed
|
||||||
TestUnit.save_log = args.save_log
|
TestUnit.save_log = args.save_log
|
||||||
|
TestUnit.print_log = args.print_log
|
||||||
TestUnit.unsafe = args.unsafe
|
TestUnit.unsafe = args.unsafe
|
||||||
|
|
||||||
# set stdout to non-blocking
|
# set stdout to non-blocking
|
||||||
@@ -381,5 +390,15 @@ class TestUnit(unittest.TestCase):
|
|||||||
if TestUnit.detailed:
|
if TestUnit.detailed:
|
||||||
fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, 0)
|
fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, 0)
|
||||||
|
|
||||||
def _print_path_to_log(self):
|
def _print_log(self, data=None):
|
||||||
print('Path to unit.log:\n' + self.testdir + '/unit.log')
|
path = self.testdir + '/unit.log'
|
||||||
|
|
||||||
|
print('Path to unit.log:\n' + path + '\n')
|
||||||
|
|
||||||
|
if TestUnit.print_log:
|
||||||
|
if data is None:
|
||||||
|
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||||
|
data = f.read()
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user