Skip to content

Commit

Permalink
Use diagnostics for failing unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimp-gh committed Aug 7, 2017
1 parent 7f16cb6 commit 74db1c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 14 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from random import random
from unittest.case import TestCase

import sys

from bzt import ToolError
from bzt.cli import CLI
from bzt.engine import SelfDiagnosable
from bzt.modules.aggregator import DataPoint, KPISet
from bzt.six import u
from bzt.utils import run_once, EXE_SUFFIX
Expand Down Expand Up @@ -105,6 +109,16 @@ def sniff_log(self, log):
self.captured_logger.addHandler(self.log_recorder)

def tearDown(self):
exc, _, _ = sys.exc_info()
if exc:
try:
if hasattr(self, 'obj') and isinstance(self.obj, SelfDiagnosable):
diags = self.obj.get_error_diagnostics()
if diags:
for line in diags:
logging.info(line)
except BaseException:
pass
if self.captured_logger:
self.captured_logger.removeHandler(self.log_recorder)
self.log_recorder.close()
Expand Down
17 changes: 1 addition & 16 deletions tests/modules/selenium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,7 @@ def configure(self, config):
self.obj.execution = self.obj.execution[0]

def tearDown(self):
exc, _, _ = sys.exc_info()
if exc:
try:
stdout_path = os.path.join(self.obj.engine.artifacts_dir, "selenium.out")
if os.path.exists(stdout_path):
stdout = open(stdout_path).read()
logging.info('Selenium stdout: """\n%s\n"""', stdout)
except BaseException:
pass
try:
stdout_path = os.path.join(self.obj.engine.artifacts_dir, "selenium.err")
if os.path.exists(stdout_path):
stderr = open(stdout_path).read()
logging.info('Selenium stderr: """\n%s\n"""', stderr)
except BaseException:
pass
super(SeleniumTestCase, self).tearDown()
if isinstance(self.obj, SeleniumExecutor):
if isinstance(self.obj.virtual_display_service, VirtualDisplay):
self.obj.virtual_display_service.free_virtual_display()

0 comments on commit 74db1c3

Please sign in to comment.