summaryrefslogtreecommitdiff
path: root/python/src/com/jetbrains/python/testing
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/com/jetbrains/python/testing')
-rw-r--r--python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java33
-rw-r--r--python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java4
-rw-r--r--python/src/com/jetbrains/python/testing/TestRunConfigurationReRunResponsible.java30
-rw-r--r--python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java5
-rw-r--r--python/src/com/jetbrains/python/testing/pytest/PyTestConfigurationProducer.java5
5 files changed, 58 insertions, 19 deletions
diff --git a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java
index 0b922514e52e..01c8ac68540c 100644
--- a/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java
+++ b/python/src/com/jetbrains/python/testing/PyRerunFailedTestsAction.java
@@ -28,33 +28,29 @@ import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsActi
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentContainer;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.search.GlobalSearchScope;
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
-/*
- * User: ktisha
- */
public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
-
protected PyRerunFailedTestsAction(@NotNull ComponentContainer componentContainer) {
super(componentContainer);
}
@Override
@Nullable
- public MyRunProfile getRunProfile() {
+ protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
final TestFrameworkRunningModel model = getModel();
- if (model == null) return null;
- final AbstractPythonRunConfiguration configuration = (AbstractPythonRunConfiguration)model.getProperties().getConfiguration();
- return new MyTestRunProfile(configuration);
+ if (model == null) {
+ return null;
+ }
+ return new MyTestRunProfile((AbstractPythonRunConfiguration)model.getProperties().getConfiguration());
}
-
private class MyTestRunProfile extends MyRunProfile {
public MyTestRunProfile(RunConfigurationBase configuration) {
@@ -71,6 +67,19 @@ public class PyRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
final AbstractPythonRunConfiguration configuration = ((AbstractPythonRunConfiguration)getPeer());
+
+ // If configuration wants to take care about rerun itself
+ if (configuration instanceof TestRunConfigurationReRunResponsible) {
+ // TODO: Extract method
+ final Set<PsiElement> failedTestElements = new HashSet<PsiElement>();
+ for (final AbstractTestProxy proxy : getFailedTests(getProject())) {
+ final Location<?> location = proxy.getLocation(getProject(), GlobalSearchScope.allScope(getProject()));
+ if (location != null) {
+ failedTestElements.add(location.getPsiElement());
+ }
+ }
+ return ((TestRunConfigurationReRunResponsible)configuration).rerunTests(executor, env, failedTestElements);
+ }
return new FailedPythonTestCommandLineStateBase(configuration, env,
(PythonTestCommandLineStateBase)configuration.getState(executor, env));
}
diff --git a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java
index 1a5aafe59051..c73a488dc7f5 100644
--- a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java
+++ b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java
@@ -63,6 +63,7 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
myConfiguration = configuration;
}
+ @Override
@NotNull
protected ConsoleView createAndAttachConsole(Project project, ProcessHandler processHandler, Executor executor)
throws ExecutionException {
@@ -89,6 +90,7 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
return new PythonTRunnerConsoleProperties(myConfiguration, executor, false);
}
+ @Override
public GeneralCommandLine generateCommandLine() throws ExecutionException {
GeneralCommandLine cmd = super.generateCommandLine();
@@ -135,7 +137,7 @@ public abstract class PythonTestCommandLineStateBase extends PythonCommandLineSt
PyRerunFailedTestsAction rerunFailedTestsAction = new PyRerunFailedTestsAction(console);
if (console instanceof SMTRunnerConsoleView) {
- rerunFailedTestsAction.init(((BaseTestsOutputConsoleView)console).getProperties(), getEnvironment());
+ rerunFailedTestsAction.init(((BaseTestsOutputConsoleView)console).getProperties());
rerunFailedTestsAction.setModelProvider(new Getter<TestFrameworkRunningModel>() {
@Override
public TestFrameworkRunningModel get() {
diff --git a/python/src/com/jetbrains/python/testing/TestRunConfigurationReRunResponsible.java b/python/src/com/jetbrains/python/testing/TestRunConfigurationReRunResponsible.java
new file mode 100644
index 000000000000..a8e9e1f8d5e4
--- /dev/null
+++ b/python/src/com/jetbrains/python/testing/TestRunConfigurationReRunResponsible.java
@@ -0,0 +1,30 @@
+package com.jetbrains.python.testing;
+
+import com.intellij.execution.ExecutionException;
+import com.intellij.execution.Executor;
+import com.intellij.execution.configurations.RunProfileState;
+import com.intellij.execution.runners.ExecutionEnvironment;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+
+/**
+ * Configuration that handles rerun failed tests itself.
+ *
+ * @author Ilya.Kazakevich
+ */
+public interface TestRunConfigurationReRunResponsible {
+ /**
+ * Rerun failed tests
+ * @param executor test executor
+ * @param environment test environment
+ * @param failedTests a pack of psi elements, indicating failed tests (to retrn)
+ * @return state to run or null if no rerun actions found (i.e. no errors in failedTest, empty etc)
+ * @throws ExecutionException failed to run
+ */
+ @Nullable
+ RunProfileState rerunTests(@NotNull final Executor executor, @NotNull final ExecutionEnvironment environment,
+ @NotNull Collection<PsiElement> failedTests) throws ExecutionException;
+}
diff --git a/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java b/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java
index 9d763e2ce286..64adf2093028 100644
--- a/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java
+++ b/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java
@@ -35,7 +35,6 @@ import com.intellij.util.ui.update.Update;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackageManager;
-import com.jetbrains.python.packaging.PyPackageManagerImpl;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;
@@ -131,9 +130,9 @@ public class VFSTestFrameworkListener implements ApplicationComponent {
LOG.info("Searching test runner in empty sdk");
return null;
}
- final PyPackageManagerImpl packageManager = (PyPackageManagerImpl)PyPackageManager.getInstance(sdk);
+ final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
try {
- return packageManager.findInstalledPackage(testPackageName) != null;
+ return packageManager.findPackage(testPackageName, false) != null;
}
catch (PyExternalProcessException e) {
LOG.info("Can't load package list " + e.getMessage());
diff --git a/python/src/com/jetbrains/python/testing/pytest/PyTestConfigurationProducer.java b/python/src/com/jetbrains/python/testing/pytest/PyTestConfigurationProducer.java
index f988dbd315e6..8dc27d4fd995 100644
--- a/python/src/com/jetbrains/python/testing/pytest/PyTestConfigurationProducer.java
+++ b/python/src/com/jetbrains/python/testing/pytest/PyTestConfigurationProducer.java
@@ -31,7 +31,6 @@ import com.intellij.webcore.packaging.PackageVersionComparator;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager;
-import com.jetbrains.python.packaging.PyPackageManagerImpl;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyFunction;
@@ -97,9 +96,9 @@ public class PyTestConfigurationProducer extends PythonTestConfigurationProducer
if (pyFunction != null) {
keywords = pyFunction.getName();
if (pyClass != null) {
- final PyPackageManagerImpl packageManager = (PyPackageManagerImpl)PyPackageManager.getInstance(sdk);
+ final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
try {
- final PyPackage pytestPackage = packageManager.findInstalledPackage("pytest");
+ final PyPackage pytestPackage = packageManager.findPackage("pytest", false);
if (pytestPackage != null && PackageVersionComparator.VERSION_COMPARATOR.compare(pytestPackage.getVersion(), "2.3.3") >= 0) {
keywords = pyClass.getName() + " and " + keywords;
}