From 11b93f437d7ac08a97c54e15b50dce99454c9c52 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Wed, 10 May 2017 17:01:24 +0300 Subject: [PATCH] PY-24047: Unittest subtest status may be Failure or Error when test failed --- python/helpers/pycharm/_jb_runner_tools.py | 2 +- .../env/unit/subtestError/test_test.py | 6 ++++ .../python/testing/PythonUnitTestingTest.java | 29 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 python/testData/testRunner/env/unit/subtestError/test_test.py diff --git a/python/helpers/pycharm/_jb_runner_tools.py b/python/helpers/pycharm/_jb_runner_tools.py index b18e99043d49..f028dff1c052 100644 --- a/python/helpers/pycharm/_jb_runner_tools.py +++ b/python/helpers/pycharm/_jb_runner_tools.py @@ -239,7 +239,7 @@ class NewTeamcityServiceMessages(_old_service_messages): # closing subtest test_name = ".".join(TREE_MANAGER.current_branch) - if self._latest_subtest_result == "Failure": + if self._latest_subtest_result in set(["Failure", "Error"]): self.testFailed(test_name) if self._latest_subtest_result == "Skip": self.testIgnored(test_name) diff --git a/python/testData/testRunner/env/unit/subtestError/test_test.py b/python/testData/testRunner/env/unit/subtestError/test_test.py new file mode 100644 index 000000000000..a7f2deb51191 --- /dev/null +++ b/python/testData/testRunner/env/unit/subtestError/test_test.py @@ -0,0 +1,6 @@ +from unittest import TestCase + +class TestThis(TestCase): + def test_this(self): + with self.subTest('test'): + raise AttributeError('should fail') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java index 63350755165a..4d1cffc38e30 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java @@ -131,6 +131,35 @@ public final class PythonUnitTestingTest extends PyEnvTestCase { }); } + + // Ensure failed and error subtests work + @Test + @EnvTestTagsRequired(tags = "python3") + public void testSubTestError() throws Exception { + runPythonTest(new PyUnitTestProcessWithConsoleTestTask("testRunner/env/unit/subtestError", "test_test.py") { + + @NotNull + @Override + protected PyUnitTestProcessRunner createProcessRunner() throws Exception { + return new PyUnitTestProcessRunner(toFullPath(myScriptName), 0); + } + + @Override + protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner, + @NotNull final String stdout, + @NotNull final String stderr, + @NotNull final String all) { + assertEquals("subtest error reported as success", "Test tree:\n" + + "[root]\n" + + ".test_test\n" + + "..TestThis\n" + + "...test_this\n" + + "....[test](-)\n", runner.getFormattedTestTree()); + } + }); + } + + /** * subtest names may have dots and shall not break test tree */