qubes/tests/run: Fix running foregin TestCases
This is needed, because when tests fail to load, unittest module generates artificial „LoadTestsFailure” class -- not based on our QubesTestCase, so it does not have .log attribute.
This commit is contained in:
parent
13b1a7201a
commit
66475e5ca7
@ -91,6 +91,12 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
return '{color[bold]}{}{color[normal]}'.format(
|
return '{color[bold]}{}{color[normal]}'.format(
|
||||||
err[0].__name__, color=self.color)
|
err[0].__name__, color=self.color)
|
||||||
|
|
||||||
|
def get_log(self, test):
|
||||||
|
try:
|
||||||
|
return test.log
|
||||||
|
except AttributeError:
|
||||||
|
return self.log
|
||||||
|
|
||||||
def getDescription(self, test): # pylint: disable=invalid-name
|
def getDescription(self, test): # pylint: disable=invalid-name
|
||||||
teststr = str(test).split('/')
|
teststr = str(test).split('/')
|
||||||
for i in range(-2, 0):
|
for i in range(-2, 0):
|
||||||
@ -112,7 +118,7 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def startTest(self, test): # pylint: disable=invalid-name
|
def startTest(self, test): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).startTest(test)
|
super(QubesTestResult, self).startTest(test)
|
||||||
test.log.critical('started')
|
self.get_log(test).critical('started')
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
if not qubes.tests.in_git:
|
if not qubes.tests.in_git:
|
||||||
self.stream.write('{}: '.format(self.hostname))
|
self.stream.write('{}: '.format(self.hostname))
|
||||||
@ -122,7 +128,7 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addSuccess(self, test): # pylint: disable=invalid-name
|
def addSuccess(self, test): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addSuccess(test)
|
super(QubesTestResult, self).addSuccess(test)
|
||||||
test.log.warning('ok')
|
self.get_log(test).warning('ok')
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln('{color[green]}ok{color[normal]}'.format(
|
self.stream.writeln('{color[green]}ok{color[normal]}'.format(
|
||||||
color=self.color))
|
color=self.color))
|
||||||
@ -132,8 +138,8 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addError(self, test, err): # pylint: disable=invalid-name
|
def addError(self, test, err): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addError(test, err)
|
super(QubesTestResult, self).addError(test, err)
|
||||||
test.log.critical('ERROR ({err[0].__name__}: {err[1]!r})'.format(
|
self.get_log(test).critical(
|
||||||
err=err))
|
'ERROR ({err[0].__name__}: {err[1]!r})'.format(err=err))
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln(
|
self.stream.writeln(
|
||||||
'{color[red]}{color[bold]}ERROR{color[normal]} ({})'.format(
|
'{color[red]}{color[bold]}ERROR{color[normal]} ({})'.format(
|
||||||
@ -146,7 +152,8 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addFailure(self, test, err): # pylint: disable=invalid-name
|
def addFailure(self, test, err): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addFailure(test, err)
|
super(QubesTestResult, self).addFailure(test, err)
|
||||||
test.log.error('FAIL ({err[0].__name__}: {err[1]!r})'.format(err=err))
|
self.get_log(test).error(
|
||||||
|
'FAIL ({err[0].__name__}: {err[1]!r})'.format(err=err))
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln('{color[red]}FAIL{color[normal]}'.format(
|
self.stream.writeln('{color[red]}FAIL{color[normal]}'.format(
|
||||||
color=self.color))
|
color=self.color))
|
||||||
@ -157,7 +164,7 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addSkip(self, test, reason): # pylint: disable=invalid-name
|
def addSkip(self, test, reason): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addSkip(test, reason)
|
super(QubesTestResult, self).addSkip(test, reason)
|
||||||
test.log.warning('skipped ({})'.format(reason))
|
self.get_log(test).warning('skipped ({})'.format(reason))
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln(
|
self.stream.writeln(
|
||||||
'{color[cyan]}skipped{color[normal]} ({})'.format(
|
'{color[cyan]}skipped{color[normal]} ({})'.format(
|
||||||
@ -169,7 +176,7 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addExpectedFailure(self, test, err): # pylint: disable=invalid-name
|
def addExpectedFailure(self, test, err): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addExpectedFailure(test, err)
|
super(QubesTestResult, self).addExpectedFailure(test, err)
|
||||||
test.log.warning('expected failure')
|
self.get_log(test).warning('expected failure')
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln(
|
self.stream.writeln(
|
||||||
'{color[yellow]}expected failure{color[normal]}'.format(
|
'{color[yellow]}expected failure{color[normal]}'.format(
|
||||||
@ -181,7 +188,7 @@ class QubesTestResult(unittest.TestResult):
|
|||||||
|
|
||||||
def addUnexpectedSuccess(self, test): # pylint: disable=invalid-name
|
def addUnexpectedSuccess(self, test): # pylint: disable=invalid-name
|
||||||
super(QubesTestResult, self).addUnexpectedSuccess(test)
|
super(QubesTestResult, self).addUnexpectedSuccess(test)
|
||||||
test.log.error('unexpected success')
|
self.get_log(test).error('unexpected success')
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln(
|
self.stream.writeln(
|
||||||
'{color[yellow]}{color[bold]}unexpected success'
|
'{color[yellow]}{color[bold]}unexpected success'
|
||||||
|
Loading…
Reference in New Issue
Block a user