From ad9f507bdbed94151f1fae1d0c9e068bd67ea290 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 5 Jun 2013 17:11:34 +0400 Subject: [PATCH] fixed PY-9527 unittests miss tcunittest --- python/helpers/pycharm/attestrunner.py | 4 ++ python/helpers/pycharm/docrunner.py | 4 ++ python/helpers/pycharm/noserunner.py | 4 ++ python/helpers/pycharm/pytest_teamcity.py | 6 ++- python/helpers/pycharm/utrunner.py | 6 +++ .../testing/PyRerunFailedTestsAction.java | 37 +++++++++++-------- .../PythonTestCommandLineStateBase.java | 7 ++++ 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/python/helpers/pycharm/attestrunner.py b/python/helpers/pycharm/attestrunner.py index 3bab7e294277..2bbd84f4e2ed 100644 --- a/python/helpers/pycharm/attestrunner.py +++ b/python/helpers/pycharm/attestrunner.py @@ -1,6 +1,10 @@ import sys, os import imp +helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) +if sys.path[0] != helpers_dir: + sys.path.insert(0, helpers_dir) + from tcunittest import TeamcityTestResult from pycharm_run_utils import import_system_module diff --git a/python/helpers/pycharm/docrunner.py b/python/helpers/pycharm/docrunner.py index 2052a0729ece..e389b9c36b0a 100644 --- a/python/helpers/pycharm/docrunner.py +++ b/python/helpers/pycharm/docrunner.py @@ -2,6 +2,10 @@ import imp import sys import datetime +helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) +if sys.path[0] != helpers_dir: + sys.path.insert(0, helpers_dir) + from tcunittest import TeamcityTestResult from tcmessages import TeamcityServiceMessages diff --git a/python/helpers/pycharm/noserunner.py b/python/helpers/pycharm/noserunner.py index 32079dbb6ee0..2db65ca11a91 100644 --- a/python/helpers/pycharm/noserunner.py +++ b/python/helpers/pycharm/noserunner.py @@ -1,5 +1,9 @@ import sys +helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) +if sys.path[0] != helpers_dir: + sys.path.insert(0, helpers_dir) + from nose_utils import TeamcityPlugin from pycharm_run_utils import debug, import_system_module diff --git a/python/helpers/pycharm/pytest_teamcity.py b/python/helpers/pycharm/pytest_teamcity.py index ca7e7371fad6..19992f8dea5d 100644 --- a/python/helpers/pycharm/pytest_teamcity.py +++ b/python/helpers/pycharm/pytest_teamcity.py @@ -1,6 +1,10 @@ -from tcmessages import TeamcityServiceMessages import os +helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) +if sys.path[0] != helpers_dir: + sys.path.insert(0, helpers_dir) + +from tcmessages import TeamcityServiceMessages from pycharm_run_utils import adjust_sys_path adjust_sys_path(False) diff --git a/python/helpers/pycharm/utrunner.py b/python/helpers/pycharm/utrunner.py index 2274c705a39b..b2e333bd6d9d 100644 --- a/python/helpers/pycharm/utrunner.py +++ b/python/helpers/pycharm/utrunner.py @@ -1,5 +1,11 @@ import sys import imp +import os + +helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) +if sys.path[0] != helpers_dir: + sys.path.insert(0, helpers_dir) + from tcunittest import TeamcityTestRunner from nose_helper import TestLoader, ContextSuite from pycharm_run_utils import import_system_module diff --git a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java index 0e3ddfcd2c4c..67da33bc7b70 100644 --- a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java +++ b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java @@ -9,11 +9,13 @@ import com.intellij.execution.configurations.RunProfileState; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Filter; +import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction; import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentContainer; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.django.testRunner.DjangoTestUtil; @@ -21,7 +23,6 @@ import com.jetbrains.django.testRunner.DjangoTestsRunConfiguration; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.run.AbstractPythonRunConfiguration; -import com.jetbrains.python.run.PythonCommandLineState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,8 +40,11 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction { } @Override + @Nullable public MyRunProfile getRunProfile() { - final AbstractPythonRunConfiguration configuration = (AbstractPythonRunConfiguration)getModel().getProperties().getConfiguration(); + final TestFrameworkRunningModel model = getModel(); + if (model == null) return null; + final AbstractPythonRunConfiguration configuration = (AbstractPythonRunConfiguration)model.getProperties().getConfiguration(); return new MyTestRunProfile(configuration); } @@ -61,9 +65,8 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction { @Override public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { final AbstractPythonRunConfiguration configuration = ((AbstractPythonRunConfiguration)getPeer()); - final PythonCommandLineState state = new FailedPythonTestCommandLineStateBase(configuration, env, + return new FailedPythonTestCommandLineStateBase(configuration, env, (PythonTestCommandLineStateBase)configuration.getState(executor, env)); - return state; } } @@ -92,19 +95,21 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction { for (AbstractTestProxy failedTest : failedTests) { if (failedTest.isLeaf()) { final Location location = failedTest.getLocation(myProject); - if (location != null) { - final PsiElement element = location.getPsiElement(); + if (location == null) continue; - if (getConfiguration() instanceof DjangoTestsRunConfiguration) { - String appName = DjangoTestUtil.getAppNameForLocation(location.getModule(), location.getPsiElement()); - String target = DjangoTestUtil.buildTargetFromLocation(appName, element); - if (target != null) - specs.add(target); - } - else { - PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false); - PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false); - String path = location.getVirtualFile().getCanonicalPath(); + final PsiElement element = location.getPsiElement(); + if (getConfiguration() instanceof DjangoTestsRunConfiguration) { + String appName = DjangoTestUtil.getAppNameForLocation(location.getModule(), location.getPsiElement()); + String target = DjangoTestUtil.buildTargetFromLocation(appName, element); + if (target != null) + specs.add(target); + } + else { + PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false); + PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false); + final VirtualFile virtualFile = location.getVirtualFile(); + if (virtualFile != null) { + String path = virtualFile.getCanonicalPath(); if (pyClass != null) path += "::" + pyClass.getName(); if (pyFunction != null) diff --git a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java index 4e7ceeae9b7c..bd855e961bc7 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java +++ b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.Collections; import java.util.List; +import java.util.Map; /** * @author yole @@ -126,6 +127,12 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt addAfterParameters(cmd); } + @Override + public void addPredefinedEnvironmentVariables(Map envs, boolean passParentEnvs) { + super.addPredefinedEnvironmentVariables(envs, passParentEnvs); + envs.put("PYCHARM_HELPERS_DIR", PythonHelpersLocator.getHelperPath("pycharm")); + } + protected abstract String getRunner(); protected abstract List getTestSpecs(); }