diff --git a/python/helpers/pycharm/django_test_runner.py b/python/helpers/pycharm/django_test_runner.py index 7492c5b9b1ed..5dbd02e05f9c 100644 --- a/python/helpers/pycharm/django_test_runner.py +++ b/python/helpers/pycharm/django_test_runner.py @@ -1,6 +1,4 @@ -import sys - -from tcunittest import TeamcityTestRunner +from tcunittest import TeamcityTestRunner, TeamcityTestResult from tcmessages import TeamcityServiceMessages from pycharm_run_utils import adjust_django_sys_path @@ -52,10 +50,41 @@ except ImportError: def __init__(self, stream=sys.stdout, **options): TeamcityTestRunner.__init__(self, stream) + +def strclass(cls): + if not cls.__name__: + return cls.__module__ + return "%s.%s" % (cls.__module__, cls.__name__) + +class DjangoTeamcityTestResult(TeamcityTestResult): + def __init__(self, *args, **kwargs): + super(DjangoTeamcityTestResult, self).__init__() + + def _getSuite(self, test): + if hasattr(test, "suite"): + suite = strclass(test.suite) + suite_location = test.suite.location + location = test.suite.abs_location + if hasattr(test, "lineno"): + location = location + ":" + str(test.lineno) + else: + location = location + ":" + str(test.test.lineno) + else: + + suite = strclass(test.__class__) + suite_location = "django_testid://" + suite + location = "django_testid://" + str(test.id()) + + return (suite, location, suite_location) + + class DjangoTeamcityTestRunner(BaseRunner): def __init__(self, stream=sys.stdout, **options): super(DjangoTeamcityTestRunner, self).__init__(stream) + def _makeResult(self, **kwargs): + return DjangoTeamcityTestResult(self.stream, **kwargs) + def build_suite(self, *args, **kwargs): EXCLUDED_APPS = getattr(settings, 'TEST_EXCLUDE', []) suite = super(DjangoTeamcityTestRunner, self).build_suite(*args, **kwargs) diff --git a/python/src/META-INF/python-core.xml b/python/src/META-INF/python-core.xml index d528e9eabc21..09920c86cb31 100644 --- a/python/src/META-INF/python-core.xml +++ b/python/src/META-INF/python-core.xml @@ -114,6 +114,7 @@ +