<commit_before>import unittest
from tcmessages import TeamcityServiceMessages
import sys, traceback, datetime
from tcunittest import strclass, TeamcityTestResult

try:
  from nose.config import Config
  from nose.result import TextTestResult
  from nose.util import isclass # backwards compat
except (Exception, ):
  e = sys.exc_info()[1]
  raise NameError("Something went wrong, do you have nosetest installed? I got this error: %s" % e)

class TeamcityNoseTestResult(TextTestResult, TeamcityTestResult):
    """TeamcityTestResult
    """
    def __init__(self, stream, descriptions, verbosity, config=None,
                 errorClasses=None):
        if errorClasses is None:
            errorClasses = {}
        self.errorClasses = errorClasses
        if config is None:
            config = Config()
        self.config = config
        self.output = stream
        self.messages = TeamcityServiceMessages(self.output, prepend_linebreak=True)
        self.messages.testMatrixEntered()
        self.current_suite = None
        TextTestResult.__init__(self, stream, descriptions, verbosity, config, errorClasses)
        TeamcityTestResult.__init__(self, stream)

    def addError(self, test, err):
        """as in nosetests
        """
        ec, ev, tb = err
        try:
            exc_info = self._exc_info_to_string(err, test)
        except TypeError:
            # 2.3 compat
            exc_info = self._exc_info_to_string(err)
        for cls, (storage, label, isfail) in self.errorClasses.items():
            #if 'Skip' in cls.__name__ or 'Skip' in ec.__name__:
            #    from nose.tools import set_trace
            #    set_trace()
            if isclass(ec) and issubclass(ec, cls):
                if isfail:
                    test.passed = False
                storage.append((test, exc_info))
                return
        self.errors.append((test, exc_info))
        test.passed = False

        err = self.formatErr(err)

        self.messages.testError(self.getTestName(test),
            message='Error', details=err)

    def is_gen(self, test):
        if hasattr(test.test, "descriptor"):
            if test.test.descriptor is not None:
                return True
        return False

    def getTestName(self, test):
        test_name_full = str(test)
        if self.is_gen(test):
            return test_name_full

        ind_1 = test_name_full.rfind('(')
        if ind_1 != -1:
          return test_name_full[:ind_1]
        ind = test_name_full.rfind('.')
        if ind != -1:
          return test_name_full[test_name_full.rfind(".") + 1:]
        return test_name_full

    def addSuccess(self, test):
        TextTestResult.addSuccess(self, test)
<commit_msg>fixed PY-7655 Error in setUpClass messes up the nose test runner<commit_after>import unittest
from tcmessages import TeamcityServiceMessages
import sys, traceback, datetime
from tcunittest import strclass, TeamcityTestResult

try:
  from nose.config import Config
  from nose.result import TextTestResult
  from nose.util import isclass # backwards compat
except (Exception, ):
  e = sys.exc_info()[1]
  raise NameError("Something went wrong, do you have nosetest installed? I got this error: %s" % e)

class TeamcityNoseTestResult(TextTestResult, TeamcityTestResult):
    """TeamcityTestResult
    """
    def __init__(self, stream, descriptions, verbosity, config=None,
                 errorClasses=None):
        if errorClasses is None:
            errorClasses = {}
        self.errorClasses = errorClasses
        if config is None:
            config = Config()
        self.config = config
        self.output = stream
        self.messages = TeamcityServiceMessages(self.output, prepend_linebreak=True)
        self.messages.testMatrixEntered()
        self.current_suite = None
        TextTestResult.__init__(self, stream, descriptions, verbosity, config, errorClasses)
        TeamcityTestResult.__init__(self, stream)

    def addError(self, test, err):
        """as in nosetests
        """
        ec, ev, tb = err
        try:
            exc_info = self._exc_info_to_string(err, test)
        except TypeError:
            # 2.3 compat
            exc_info = self._exc_info_to_string(err)
        for cls, (storage, label, isfail) in self.errorClasses.items():
            #if 'Skip' in cls.__name__ or 'Skip' in ec.__name__:
            #    from nose.tools import set_trace
            #    set_trace()
            if isclass(ec) and issubclass(ec, cls):
                if isfail:
                    test.passed = False
                storage.append((test, exc_info))
                return
        self.errors.append((test, exc_info))
        test.passed = False

        err = self.formatErr(err)

        self.messages.testError(self.getTestName(test),
            message='Error', details=err)

    def is_gen(self, test):
        if hasattr(test, "test") and hasattr(test.test, "descriptor"):
            if test.test.descriptor is not None:
                return True
        return False

    def getTestName(self, test):
        if hasattr(test, "error_context"):
          return test.error_context
        test_name_full = str(test)
        if self.is_gen(test):
            return test_name_full

        ind_1 = test_name_full.rfind('(')
        if ind_1 != -1:
          return test_name_full[:ind_1]
        ind = test_name_full.rfind('.')
        if ind != -1:
          return test_name_full[test_name_full.rfind(".") + 1:]
        return test_name_full

    def addSuccess(self, test):
        TextTestResult.addSuccess(self, test)

{'fraction_non_alphanumeric': 0.09102288984263233, 'fraction_numerical': 0.003934191702432046, 'mean_word_length': 2.2958161461402473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7469881', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1584, 'n_words': 416}