From f79f77c87af0b46eb2c2f0717633e5b933f0d860 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 14 Feb 2011 15:24:31 +0300 Subject: [PATCH] fixed PY-2807 for test functions and for test generators (Running and re-running single test cases or test methods from nosetests runner) --- python/helpers/pycharm/nose_utils.py | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/python/helpers/pycharm/nose_utils.py b/python/helpers/pycharm/nose_utils.py index cb1eafc7445d..0d55e441b41c 100644 --- a/python/helpers/pycharm/nose_utils.py +++ b/python/helpers/pycharm/nose_utils.py @@ -96,9 +96,39 @@ class TeamcityNoseTestResult(TextTestResult, TeamcityTestResult): else: suite = strclass(test.__class__) suite_location = "python_uttestid://" + suite - location = "python_uttestid://" + str(test.id()) + try: + from nose_helper.util import func_lineno + + if hasattr(test.test, "descriptor") and test.test.descriptor: + location = "file://"+self.test_address(test.test.descriptor)+":"+str(func_lineno(test.test.descriptor)) + else: + location = "file://"+self.test_address(test.test.test)+":"+str(func_lineno(test.test.test)) + except: + location = "python_uttestid://" + str(test.id()) return (location, suite_location) + def test_address(self, test): + """Find the test address for a test, which may be a module, filename, + class, method or function. + """ + if hasattr(test, "address"): + return test.address()[0] + t = type(test) + file = None + import types, os + if (t == types.FunctionType or issubclass(t, type) or t == type + or isclass(test)): + module = getattr(test, '__module__', None) + if module is not None: + m = sys.modules[module] + file = getattr(m, '__file__', None) + if file is not None: + file = os.path.abspath(file) + if file.endswith("pyc"): + file = file[:-1] + return file + raise TypeError("I don't know what %s is (%s)" % (test, t)) + def getSuiteName(self, test): test_name_full = str(test)