diff --git a/python/helpers/pycharm/_jb_runner_tools.py b/python/helpers/pycharm/_jb_runner_tools.py index cce7cc6190a6..7b09e6a50ba6 100644 --- a/python/helpers/pycharm/_jb_runner_tools.py +++ b/python/helpers/pycharm/_jb_runner_tools.py @@ -214,23 +214,13 @@ class NewTeamcityServiceMessages(_old_service_messages): test_name = ".".join(TREE_MANAGER.current_branch) if self._latest_subtest_result == "Failure": self.testFailed(test_name) + if self._latest_subtest_result == "Skip": + self.testIgnored(test_name) self.testFinished(test_name) self._latest_subtest_result = None - def testIgnored(self, testName, message='', flowId=None): - import re - # Skipped subtest of unittest in format "test_name.test_name (subtestInfo)" should be processed as special case: - # start, ignore like test_name.test_name.(subtestInfo), stop - match_result = re.match(r"^([^(]+\s)*([(][^)]+[)])$", str(testName)) - if match_result: - test_to_skip = ".".join(TREE_MANAGER.current_branch + [match_result.group(2)]) - self.testStarted(test_to_skip) - super(NewTeamcityServiceMessages, self).testIgnored(test_to_skip, message, flowId) - self.testFinished(test_to_skip) - else: - super(NewTeamcityServiceMessages, self).testIgnored(testName, message, flowId) # For all other cases leave same behaviour def subTestBlockOpened(self, name, subTestResult, flowId=None): self.testStarted(".".join(TREE_MANAGER.current_branch + [name])) diff --git a/python/helpers/pycharm/teamcity/unittestpy.py b/python/helpers/pycharm/teamcity/unittestpy.py index 4cbfa0447766..90f56e944769 100644 --- a/python/helpers/pycharm/teamcity/unittestpy.py +++ b/python/helpers/pycharm/teamcity/unittestpy.py @@ -22,7 +22,8 @@ class TeamcityTestResult(TestResult): self.subtest_failures = {} self.messages = TeamcityServiceMessages(_real_stdout) - def get_test_id(self, test): + @staticmethod + def get_test_id(test): if is_string(test): return test @@ -46,17 +47,40 @@ class TeamcityTestResult(TestResult): self.messages.testIgnored(test_id, message="Expected failure: " + err, flowId=test_id) + def get_subtest_block_id(self, test, subtest): + test_id = self.get_test_id(test) + subtest_id = self.get_test_id(subtest) + + if subtest_id.startswith(test_id): + block_id = subtest_id[len(test_id):].strip() + else: + block_id = subtest_id + if len(block_id) == 0: + block_id = test_id + return block_id + def addSkip(self, test, reason=""): if sys.version_info >= (2, 7): super(TeamcityTestResult, self).addSkip(test, reason) - test_id = self.get_test_id(test) - if reason: reason_str = ": " + str(reason) else: reason_str = "" - self.messages.testIgnored(test_id, message="Skipped" + reason_str, flowId=test_id) + + if get_class_fullname(test) == "unittest.case._SubTest": + parent_test = test.test_case + parent_test_id = self.get_test_id(parent_test) + subtest = test + + block_id = self.get_subtest_block_id(parent_test, subtest) + + self.messages.subTestBlockOpened(block_id, subTestResult="Skip", flowId=parent_test_id) + self.messages.testStdOut(parent_test_id, out="SubTest skipped" + reason_str + "\n", flowId=parent_test_id) + self.messages.blockClosed(block_id, flowId=parent_test_id) + else: + test_id = self.get_test_id(test) + self.messages.testIgnored(test_id, message="Skipped" + reason_str, flowId=test_id) def addUnexpectedSuccess(self, test): super(TeamcityTestResult, self).addUnexpectedSuccess(test)