mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-23416: Do not provide pattern to using test for rerun
Pattern can't be used with concrete tests names are provided (as it done for rerun)
This commit is contained in:
@@ -51,7 +51,7 @@ class PyUniversalNoseTestConfiguration(project: Project, factory: PyUniversalNos
|
||||
override fun createConfigurationEditor(): SettingsEditor<PyUniversalTestConfiguration> =
|
||||
PyUniversalNoseTestSettingsEditor(this)
|
||||
|
||||
override fun getCustomRawArgumentsString(): String =
|
||||
override fun getCustomRawArgumentsString(forRerun: Boolean): String =
|
||||
when {
|
||||
regexPattern.isEmpty() -> ""
|
||||
else -> "-m $regexPattern"
|
||||
|
||||
@@ -49,7 +49,7 @@ class PyUniversalPyTestConfiguration(project: Project, factory: PyUniversalPyTes
|
||||
override fun createConfigurationEditor(): SettingsEditor<PyUniversalTestConfiguration> =
|
||||
PyUniversalPyTestSettingsEditor(this)
|
||||
|
||||
override fun getCustomRawArgumentsString(): String =
|
||||
override fun getCustomRawArgumentsString(forRerun: Boolean): String =
|
||||
when {
|
||||
keywords.isEmpty() -> ""
|
||||
else -> "-k $keywords"
|
||||
|
||||
@@ -478,7 +478,7 @@ abstract class PyUniversalTestConfiguration(project: Project,
|
||||
locations.map { it.first }.distinctBy { it.psiElement }.map { getTestSpecForPythonTarget(it) }.filterNotNull().forEach {
|
||||
result.addAll(it)
|
||||
}
|
||||
return result + generateRawArguments()
|
||||
return result + generateRawArguments(true)
|
||||
}
|
||||
|
||||
fun getTestSpec(): List<String> {
|
||||
@@ -488,8 +488,8 @@ abstract class PyUniversalTestConfiguration(project: Project,
|
||||
/**
|
||||
* raw arguments to be added after "--" and passed to runner directly
|
||||
*/
|
||||
private fun generateRawArguments(): List<String> {
|
||||
val rawArguments = additionalArguments + " " + getCustomRawArgumentsString()
|
||||
private fun generateRawArguments(forRerun: Boolean = false): List<String> {
|
||||
val rawArguments = additionalArguments + " " + getCustomRawArgumentsString(forRerun)
|
||||
if (rawArguments.isNotBlank()) {
|
||||
return listOf("--") + getParsedAdditionalArguments(project, rawArguments)
|
||||
}
|
||||
@@ -514,7 +514,7 @@ abstract class PyUniversalTestConfiguration(project: Project,
|
||||
/**
|
||||
* @return configuration-specific arguments
|
||||
*/
|
||||
protected open fun getCustomRawArgumentsString() = ""
|
||||
protected open fun getCustomRawArgumentsString(forRerun: Boolean = false) = ""
|
||||
|
||||
fun reset() {
|
||||
target.target = DEFAULT_PATH
|
||||
|
||||
@@ -54,11 +54,12 @@ class PyUniversalUnitTestConfiguration(project: Project, factory: PyUniversalUni
|
||||
override fun createConfigurationEditor(): SettingsEditor<PyUniversalTestConfiguration> =
|
||||
PyUniversalUnitTestSettingsEditor(this)
|
||||
|
||||
override fun getCustomRawArgumentsString(): String {
|
||||
override fun getCustomRawArgumentsString(forRerun: Boolean): String {
|
||||
// Pattern can only be used with folders ("all in folder" in legacy terms)
|
||||
if ((!pattern.isNullOrEmpty()) && target.targetType != TestTargetType.CUSTOM) {
|
||||
val path = LocalFileSystem.getInstance().findFileByPath(target.target) ?: return ""
|
||||
return if (path.isDirectory) "-p $pattern" else ""
|
||||
// "Pattern" works only for "discovery" mode and for "rerun" we are using "python" targets ("concrete" tests)
|
||||
return if (path.isDirectory && !forRerun) "-p $pattern" else ""
|
||||
}
|
||||
else {
|
||||
return ""
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
class FooTest(TestCase):
|
||||
def test_test(self):
|
||||
pass
|
||||
|
||||
def test_2_test(self):
|
||||
self.fail()
|
||||
@@ -60,6 +60,40 @@ public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure test rerun works when pattern is enabled (PY-23416)
|
||||
*/
|
||||
@Test
|
||||
public void testPatternRerun() throws Exception {
|
||||
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/patternRerun", ".") {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
|
||||
// Full pass is required because it is folder
|
||||
return new PyUnitTestProcessRunner(toFullPath(myScriptName), 2) {
|
||||
@Override
|
||||
protected void configurationCreatedAndWillLaunch(@NotNull final PyUniversalUnitTestConfiguration configuration) throws IOException {
|
||||
super.configurationCreatedAndWillLaunch(configuration);
|
||||
configuration.setPattern("test*");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
|
||||
@NotNull final String stdout,
|
||||
@NotNull final String stderr,
|
||||
@NotNull final String all) {
|
||||
if (runner.getCurrentRerunStep() == 0) {
|
||||
Assert.assertEquals(stderr, 2, runner.getAllTestsCount());
|
||||
}
|
||||
else {
|
||||
Assert.assertEquals(stderr, 1, runner.getAllTestsCount());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
|
||||
Reference in New Issue
Block a user