From a67392af469d6cb95be554baf69fd9e6288bb5b9 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 8 Nov 2010 13:49:29 +0300 Subject: [PATCH] added py.test support for versions >= 1.0 fixed location for unittests --- python/helpers/pycharm/nose_helper/case.py | 4 +- python/helpers/pycharm/tcunittest.py | 12 +++--- python/helpers/pytest_teamcity.py | 38 ++++++++++++++----- .../pytest/PyTestRunConfiguration.java | 4 ++ 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/python/helpers/pycharm/nose_helper/case.py b/python/helpers/pycharm/nose_helper/case.py index 2d084d02d384..2403c716cceb 100644 --- a/python/helpers/pycharm/nose_helper/case.py +++ b/python/helpers/pycharm/nose_helper/case.py @@ -119,7 +119,7 @@ class FunctionTestCase(TestBase): return func.__module__ else: #TODO[kate]: get module of function in jython < 2.2 - return "Unknown module" + return "Unknown module." def _descriptors(self): """In most cases, this is the function itself and no arguments. For @@ -161,7 +161,7 @@ class MethodTestCase(TestBase): return "%s.%s" % (func.__module__, self.cls.__name__) else: #TODO[kate]: get module of function in jython < 2.2 - return "Unknown module" + return "Unknown module." def __str__(self): func, arg = self._descriptors() diff --git a/python/helpers/pycharm/tcunittest.py b/python/helpers/pycharm/tcunittest.py index 8b99d0a80ffa..666a4063741d 100644 --- a/python/helpers/pycharm/tcunittest.py +++ b/python/helpers/pycharm/tcunittest.py @@ -26,10 +26,6 @@ class TeamcityTestResult(TestResult): if test._testMethodName == "runTest": return str(test) return test._testMethodName - elif hasattr(test, '__testMethodName'): - if test.__testMethodName == "runTest": - return str(test) - return test.__testMethodName else: return str(test) @@ -66,8 +62,12 @@ class TeamcityTestResult(TestResult): self.current_suite = suite self.messages.testSuiteStarted(strclass(self.current_suite), location="python_uttestid://" + strclass(self.current_suite)) setattr(test, "startTime", datetime.datetime.now()) - self.messages.testStarted(self.getTestName(test), location="python_uttestid://" + str(test.id())) - + if hasattr(test, "test"): + id = test.id()[:test.id().find("..") + 1] + test.test.__name__ + else: + id = test.id() + self.messages.testStarted(self.getTestName(test), location="python_uttestid://" + str(id)) + def stopTest(self, test): start = getattr(test, "startTime", datetime.datetime.now()) d = datetime.datetime.now() - start diff --git a/python/helpers/pytest_teamcity.py b/python/helpers/pytest_teamcity.py index 35e2b3d97e71..335733b8c6f8 100644 --- a/python/helpers/pytest_teamcity.py +++ b/python/helpers/pytest_teamcity.py @@ -7,21 +7,39 @@ def fspath_to_url(fspath): return "file:///" + str(fspath).replace("\\", "/") def pytest_collectstart(collector): - messages.testSuiteStarted(collector.name, location=fspath_to_url(collector.fspath)) + if collector.name != "()": + messages.testSuiteStarted(collector.name, location=fspath_to_url(collector.fspath)) def pytest_runtest_makereport(item, call): if call.when == "setup": fspath, lineno, msg = item.reportinfo() url = fspath_to_url(fspath) if lineno: url += ":" + str(lineno) - messages.testStarted(item.name, location=url) + # messages.testStarted(item.name, location=url) -def pytest_runtest_logreport(rep): - if rep.failed: - messages.testFailed(rep.item.name, details=rep.longrepr) - elif rep.skipped: - messages.testIgnored(rep.item.name) - messages.testFinished(rep.item.name) +def pytest_runtest_logreport(report): + if report.item._args: + name = report.item.function.__name__ + str(report.item._args) + else: + name = report.item.name + if report.failed: + messages.testFailed(name, details=report.longrepr) + elif report.skipped: + messages.testIgnored(name) + messages.testFinished(name) -def pytest_collectreport(rep): - messages.testSuiteFinished(rep.collector.name) +def pytest_collectreport(report): + if report.collector.name != "()": + messages.testSuiteFinished(report.collector.name) + +def pytest_itemstart(item, node=None): + print item.__dict__ + if item._args: + name = item.function.__name__ + str(item._args) + else: + name = item.name + if hasattr(item, "_fslineno"): + path = fspath_to_url(item._fslineno[0]) + ":" + str(item._fslineno[1] + 1) + else: + path = fspath_to_url(item.fspath) + messages.testStarted(name, location=path) diff --git a/python/src/com/jetbrains/python/testing/pytest/PyTestRunConfiguration.java b/python/src/com/jetbrains/python/testing/pytest/PyTestRunConfiguration.java index ee11360cee75..2ee36d3c81eb 100644 --- a/python/src/com/jetbrains/python/testing/pytest/PyTestRunConfiguration.java +++ b/python/src/com/jetbrains/python/testing/pytest/PyTestRunConfiguration.java @@ -100,6 +100,10 @@ public class PyTestRunConfiguration extends AbstractPythonRunConfiguration { if (runner.exists()) return runner.getPath(); runner = new File(new File(bin_dir.getParentFile(), "scripts"), PY_TEST); if (runner.exists()) return runner.getPath(); + runner = new File(new File(bin_dir.getParentFile(), "local"), PY_TEST); + if (runner.exists()) return runner.getPath(); + runner = new File(new File (new File(bin_dir.getParentFile(), "local"), "bin"), PY_TEST); + if (runner.exists()) return runner.getPath(); return null; } }