mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Test stoud fixed for PY-12621
This commit is contained in:
@@ -80,6 +80,7 @@ if PYVERSION > [1, 4, 0]:
|
||||
messages.testIgnored(name)
|
||||
elif report.failed:
|
||||
messages.testFailed(name, details=report.longrepr)
|
||||
messages.testFinished(name) # We need to mark it finished even if it failed to display it at parent node
|
||||
elif report.when == "call":
|
||||
messages.testFinished(name)
|
||||
|
||||
|
||||
@@ -20,10 +20,13 @@ def get_plugin_manager():
|
||||
from _pytest.core import PluginManager
|
||||
return PluginManager(load=True)
|
||||
|
||||
# "-s" is always required: no test output provided otherwise
|
||||
args = sys.argv[1:]
|
||||
args.append("-s") if "-s" not in args else None
|
||||
|
||||
if has_pytest:
|
||||
_preinit = []
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
_pluginmanager = get_plugin_manager()
|
||||
hook = _pluginmanager.hook
|
||||
try:
|
||||
@@ -38,7 +41,6 @@ if has_pytest:
|
||||
|
||||
else:
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
config = py.test.config
|
||||
try:
|
||||
config.parse(args)
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
class TestPyTest:
|
||||
def testOne(self):
|
||||
print("I am test1")
|
||||
assert 5 == 2*2
|
||||
|
||||
def testTwo(self):
|
||||
assert True
|
||||
|
||||
def testFail(self):
|
||||
print("I will fail")
|
||||
assert False
|
||||
|
||||
def testThree():
|
||||
assert 4 == 2*2
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.jetbrains.env.python.testing;
|
||||
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.ut.PyTestTestTask;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class PythonPyTestingTest extends PyEnvTestCase{
|
||||
public class PythonPyTestingTest extends PyEnvTestCase {
|
||||
public void testPytestRunner() {
|
||||
runPythonTest(new PyTestTestTask("/testRunner/env/pytest", "test1.py") {
|
||||
|
||||
@@ -24,9 +26,12 @@ public class PythonPyTestingTest extends PyEnvTestCase{
|
||||
|
||||
@Override
|
||||
public void after() {
|
||||
assertEquals(8, allTestsCount());
|
||||
assertEquals(9, allTestsCount());
|
||||
assertEquals(5, passedTestsCount());
|
||||
assertEquals(3, failedTestsCount());
|
||||
assertEquals(4, failedTestsCount());
|
||||
Assert.assertThat("No test stdout", getMockPrinter(findTestByName("testOne")).getStdOut(), Matchers.startsWith("I am test1"));
|
||||
// Ensure test has stdout even it fails
|
||||
Assert.assertThat("No stdout for fail", getMockPrinter(findTestByName("testFail")).getStdOut(), Matchers.startsWith("I will fail"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+52
-1
@@ -13,8 +13,11 @@ import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
|
||||
import com.intellij.execution.runners.ProgramRunner;
|
||||
import com.intellij.execution.testframework.AbstractTestProxy;
|
||||
import com.intellij.execution.testframework.Filter;
|
||||
import com.intellij.execution.testframework.Printable;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.MockPrinter;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.TestResultsViewer;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
@@ -190,7 +193,7 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask {
|
||||
* Run configuration.
|
||||
*
|
||||
* @param settings settings (if have any, null otherwise)
|
||||
* @param config configuration to run
|
||||
* @param config configuration to run
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void runConfiguration(@Nullable final RunnerAndConfigurationSettings settings,
|
||||
@@ -271,6 +274,54 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask {
|
||||
Assert.assertEquals(output(), 0, failedTestsCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link MockPrinter} filled with test output. Use it to check what output test has.
|
||||
*
|
||||
* @param test test to fill mock printer with
|
||||
* @return filled print.
|
||||
*/
|
||||
@NotNull
|
||||
protected static MockPrinter getMockPrinter(@NotNull final Printable test) {
|
||||
final MockPrinter printer = new MockPrinter();
|
||||
test.printOn(printer);
|
||||
return printer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for test by its name recursevly in {@link #myTestProxy}
|
||||
*
|
||||
* @param testName test name to find
|
||||
* @return test
|
||||
* @throws AssertionError if no test found
|
||||
*/
|
||||
@NotNull
|
||||
public AbstractTestProxy findTestByName(@NotNull final String testName) {
|
||||
final AbstractTestProxy test = findTestByName(testName, myTestProxy);
|
||||
assert test != null : "No test found with name" + testName;
|
||||
return test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for test by its name recursevly in test, passed as arumuent.
|
||||
*
|
||||
* @param testName test name to find
|
||||
* @param test root test
|
||||
* @return test or null if not found
|
||||
*/
|
||||
@Nullable
|
||||
private static AbstractTestProxy findTestByName(@NotNull final String testName, @NotNull final AbstractTestProxy test) {
|
||||
if (test.getName().equals(testName)) {
|
||||
return test;
|
||||
}
|
||||
for (final AbstractTestProxy testProxy : test.getChildren()) {
|
||||
final AbstractTestProxy result = findTestByName(testName, testProxy);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int failedTestsCount() {
|
||||
return myTestProxy.collectChildren(NOT_SUIT.and(Filter.FAILED_OR_INTERRUPTED)).size();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user