mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-22 06:21:25 +07:00
PY-23785: support unittest2, PY-23846: support dots in subtest names
Leonid's runners updated to support unittest2 and dots in subtests
This commit is contained in:
@@ -17,6 +17,9 @@ class TeamcityTestResult(TestResult):
|
||||
def __init__(self, stream=_real_stdout, descriptions=None, verbosity=None):
|
||||
super(TeamcityTestResult, self).__init__()
|
||||
|
||||
# Some code may ask for self.failfast, see unittest2.case.TestCase.subTest
|
||||
self.failfast = getattr(self, "failfast", False)
|
||||
|
||||
self.test_started_datetime_map = {}
|
||||
self.failed_tests = set()
|
||||
self.subtest_failures = {}
|
||||
@@ -40,7 +43,9 @@ class TeamcityTestResult(TestResult):
|
||||
super(TeamcityTestResult, self).addSuccess(test)
|
||||
|
||||
def addExpectedFailure(self, test, err):
|
||||
super(TeamcityTestResult, self).addExpectedFailure(test, err)
|
||||
_super = super(TeamcityTestResult, self)
|
||||
if hasattr(_super, "addExpectedFailure"):
|
||||
_super.addExpectedFailure(test, err)
|
||||
|
||||
err = convert_error_to_string(err)
|
||||
test_id = self.get_test_id(test)
|
||||
@@ -68,7 +73,8 @@ class TeamcityTestResult(TestResult):
|
||||
else:
|
||||
reason_str = ""
|
||||
|
||||
if get_class_fullname(test) == "unittest.case._SubTest":
|
||||
test_class_name = get_class_fullname(test)
|
||||
if test_class_name == "unittest.case._SubTest" or test_class_name == "unittest2.case._SubTest":
|
||||
parent_test = test.test_case
|
||||
parent_test_id = self.get_test_id(parent_test)
|
||||
subtest = test
|
||||
@@ -83,7 +89,9 @@ class TeamcityTestResult(TestResult):
|
||||
self.messages.testIgnored(test_id, message="Skipped" + reason_str, flowId=test_id)
|
||||
|
||||
def addUnexpectedSuccess(self, test):
|
||||
super(TeamcityTestResult, self).addUnexpectedSuccess(test)
|
||||
_super = super(TeamcityTestResult, self)
|
||||
if hasattr(_super, "addUnexpectedSuccess"):
|
||||
_super.addUnexpectedSuccess(test)
|
||||
|
||||
test_id = self.get_test_id(test)
|
||||
self.messages.testFailed(test_id, message='Failure',
|
||||
@@ -93,7 +101,8 @@ class TeamcityTestResult(TestResult):
|
||||
def addError(self, test, err, *k):
|
||||
super(TeamcityTestResult, self).addError(test, err)
|
||||
|
||||
if get_class_fullname(test) == "unittest.suite._ErrorHolder":
|
||||
test_class = get_class_fullname(test)
|
||||
if test_class == "unittest.suite._ErrorHolder" or test_class == "unittest2.suite._ErrorHolder":
|
||||
# This is a standalone error
|
||||
|
||||
test_name = test.id()
|
||||
@@ -120,13 +129,17 @@ class TeamcityTestResult(TestResult):
|
||||
self.report_fail(test, 'Failure', err)
|
||||
|
||||
def addSubTest(self, test, subtest, err):
|
||||
super(TeamcityTestResult, self).addSubTest(test, subtest, err)
|
||||
_super = super(TeamcityTestResult, self)
|
||||
if hasattr(_super, "addSubTest"):
|
||||
_super.addSubTest(test, subtest, err)
|
||||
|
||||
test_id = self.get_test_id(test)
|
||||
subtest_id = self.get_test_id(subtest)
|
||||
|
||||
if subtest_id.startswith(test_id):
|
||||
block_id = subtest_id[len(test_id):].strip()
|
||||
# Replace "." -> "_" since '.' is a test hierarchy separator
|
||||
# See i.e. https://github.com/JetBrains/teamcity-messages/issues/134 (https://youtrack.jetbrains.com/issue/PY-23846)
|
||||
block_id = subtest_id[len(test_id):].strip().replace(".", "_")
|
||||
else:
|
||||
block_id = subtest_id
|
||||
if len(block_id) == 0:
|
||||
|
||||
@@ -12,8 +12,8 @@ envs {
|
||||
packages = ["pip", "setuptools"]
|
||||
_64Bits = true
|
||||
|
||||
conda "django19", "2.7", ["django==1.9", "tox", "nose", "pytest", "behave", "lettuce>=0.2.22"], true
|
||||
textfile "django19/tags.txt", "python2.7\ndjango\nnose\npytest\nbehave\nlettuce\npackaging\ntox"
|
||||
conda "django19", "2.7", ["django==1.9", "tox", "nose", "pytest", "behave", "lettuce>=0.2.22", "unittest2"], true
|
||||
textfile "django19/tags.txt", "python2.7\ndjango\nnose\npytest\nbehave\nlettuce\npackaging\ntox\nunittest2"
|
||||
|
||||
conda "django110", "3.4", ["django==1.10", "django-nose"], false
|
||||
textfile "django110/tags.txt", "python3.4\ndjango\nskeletons\ndjango-nose"
|
||||
|
||||
9
python/testData/testRunner/env/unit/subtestDots/test_test.py
vendored
Normal file
9
python/testData/testRunner/env/unit/subtestDots/test_test.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import unittest
|
||||
|
||||
|
||||
class SampleTest(unittest.TestCase):
|
||||
|
||||
def test_sample(self):
|
||||
for i in range(10):
|
||||
with self.subTest(i=str(i)+'.'+str(i)):
|
||||
self.assertTrue(i > 1)
|
||||
10
python/testData/testRunner/env/unit/unittest2/test_test.py
vendored
Normal file
10
python/testData/testRunner/env/unit/unittest2/test_test.py
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
from unittest2 import TestCase
|
||||
|
||||
|
||||
class SampleTest(TestCase):
|
||||
|
||||
def test_sample(self):
|
||||
for i in range(10):
|
||||
with self.subTest(i=i):
|
||||
self.assertTrue(i > 3)
|
||||
@@ -51,6 +51,82 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
|
||||
|
||||
/**
|
||||
* subtest names may have dots and shall not break test tree
|
||||
*/
|
||||
@EnvTestTagsRequired(tags = "python3")
|
||||
@Test
|
||||
public void testDotsInSubtest() throws Exception {
|
||||
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/subtestDots", "test_test.py") {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
|
||||
return new PyUnitTestProcessRunner(toFullPath(myScriptName), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
|
||||
@NotNull final String stdout,
|
||||
@NotNull final String stderr,
|
||||
@NotNull final String all) {
|
||||
runner.getFormattedTestTree();
|
||||
assertEquals("dots in subtest names broke output", "Test tree:\n" +
|
||||
"[root]\n" +
|
||||
".test_test\n" +
|
||||
"..SampleTest\n" +
|
||||
"...test_sample\n" +
|
||||
"....(i='0_0')(-)\n" +
|
||||
"....(i='1_1')(-)\n" +
|
||||
"....(i='2_2')(+)\n" +
|
||||
"....(i='3_3')(+)\n" +
|
||||
"....(i='4_4')(+)\n" +
|
||||
"....(i='5_5')(+)\n" +
|
||||
"....(i='6_6')(+)\n" +
|
||||
"....(i='7_7')(+)\n" +
|
||||
"....(i='8_8')(+)\n" +
|
||||
"....(i='9_9')(+)\n", runner.getFormattedTestTree());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EnvTestTagsRequired(tags = "unittest2")
|
||||
@Test
|
||||
public void testUnitTest2() throws Exception {
|
||||
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/unittest2", "test_test.py") {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
|
||||
return new PyUnitTestProcessRunner(toFullPath(myScriptName), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
|
||||
@NotNull final String stdout,
|
||||
@NotNull final String stderr,
|
||||
@NotNull final String all) {
|
||||
runner.getFormattedTestTree();
|
||||
assertEquals("unittest2 produced wrong tree", "Test tree:\n" +
|
||||
"[root]\n" +
|
||||
".test_test\n" +
|
||||
"..SampleTest\n" +
|
||||
"...test_sample\n" +
|
||||
"....(i=0)(-)\n" +
|
||||
"....(i=1)(-)\n" +
|
||||
"....(i=2)(-)\n" +
|
||||
"....(i=3)(-)\n" +
|
||||
"....(i=4)(+)\n" +
|
||||
"....(i=5)(+)\n" +
|
||||
"....(i=6)(+)\n" +
|
||||
"....(i=7)(+)\n" +
|
||||
"....(i=8)(+)\n" +
|
||||
"....(i=9)(+)\n", runner.getFormattedTestTree());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Ensures setup/teardown does not break anything
|
||||
@Test
|
||||
public void testSetupTearDown() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user