tox test fix: bad names for broken tests in nose

This commit is contained in:
Ilya.Kazakevich
2016-01-16 03:18:29 +03:00
parent 793dea71bf
commit 0f0774f40e
+21 -15
View File
@@ -9,6 +9,7 @@ from tcunittest import TeamcityTestResult
try:
from nose.failure import Failure
from nose.util import isclass # backwards compat
from nose.config import Config
from nose.result import TextTestResult
@@ -17,7 +18,7 @@ try:
except (Exception, ):
e = sys.exc_info()[1]
raise NameError(
"Something went wrong, do you have nosetest installed? I got this error: %s" % e)
"Something went wrong, do you have nosetest installed? I got this error: %s" % e)
class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
"""
@@ -39,11 +40,11 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
self.config = config
self.output = stream
self.messages = TeamcityServiceMessages(self.output,
prepend_linebreak=True)
prepend_linebreak=True)
self.messages.testMatrixEntered()
self.current_suite = None
TextTestResult.__init__(self, stream, descriptions, verbosity, config,
errorClasses)
errorClasses)
TeamcityTestResult.__init__(self, stream)
def configure(self, options, conf):
@@ -55,10 +56,11 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
def addError(self, test, err):
exctype, value, tb = err
err = self.formatErr(err)
if exctype == SkipTest:
self.messages.testIgnored(self.getTestName(test), message='Skip')
self.messages.testIgnored(self.getTestName(test), message='Skip')
else:
self.messages.testError(self.getTestName(test), message='Error', details=err, duration=self.__getDuration(test))
self.messages.testError(self.getTestName(test), message='Error', details=err, duration=self.__getDuration(test))
def formatErr(self, err):
exctype, value, tb = err
@@ -77,6 +79,8 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
def getTestName(self, test):
if isinstance(test.test, Failure):
return "ERROR"
if hasattr(test, "error_context"):
return test.error_context
test_name_full = str(test)
@@ -93,7 +97,7 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
err = self.formatErr(err)
self.messages.testFailed(self.getTestName(test),
message='Failure', details=err)
message='Failure', details=err)
def addSkip(self, test, reason):
@@ -117,14 +121,14 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
if hasattr(test.test, "descriptor") and test.test.descriptor:
suite_location = "file://" + self.test_address(
test.test.descriptor)
test.test.descriptor)
location = suite_location + ":" + str(
func_lineno(test.test.descriptor))
func_lineno(test.test.descriptor))
else:
suite_location = "file://" + self.test_address(
test.test.test)
test.test.test)
location = "file://" + self.test_address(
test.test.test) + ":" + str(func_lineno(test.test.test))
test.test.test) + ":" + str(func_lineno(test.test.test))
except:
test_id = test.id()
suite_id = test_id[:test_id.rfind(".")]
@@ -155,6 +159,8 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
def getSuiteName(self, test):
if isinstance(test.test, Failure):
return "ERROR"
test_name_full = str(test)
ind_1 = test_name_full.rfind('(')
@@ -179,7 +185,7 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
self.messages.testSuiteFinished(self.current_suite)
self.current_suite = suite
self.messages.testSuiteStarted(self.current_suite,
location=suite_location)
location=suite_location)
setattr(test, "startTime", datetime.datetime.now())
self.messages.testStarted(self.getTestName(test), location=location)
@@ -187,7 +193,7 @@ class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
def stopTest(self, test):
duration = self.__getDuration(test)
self.messages.testFinished(self.getTestName(test),
duration=int(duration))
duration=int(duration))
def __getDuration(self, test):
start = getattr(test, "startTime", datetime.datetime.now())
@@ -216,9 +222,9 @@ class TeamcityNoseRunner(unittest.TextTestRunner):
def _makeResult(self):
return TeamcityPlugin(self.stream,
self.descriptions,
self.verbosity,
self.config)
self.descriptions,
self.verbosity,
self.config)
def run(self, test):
"""Overrides to provide plugin hooks and defer all output to