PY-16484 custom test suite do not have some required proprties, but still should...
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 11 Sep 2015 19:09:27 +0000 (22:09 +0300)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 11 Sep 2015 19:09:27 +0000 (22:09 +0300)
python/helpers/pycharm/tcunittest.py
python/testData/testRunner/env/unit/test_load_protocol.py [new file with mode: 0644]
python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java

index c94b76d5c285dd930234ca7ecbbd007173b3041f..b688d804c653e1c07b069fda31a3cae7fb1c5ccb 100644 (file)
@@ -152,7 +152,7 @@ class TeamcityTestResult(TestResult):
     self.messages.testIgnored(self.getTestName(test), message=reason)
 
   def _getSuite(self, test):
-    if hasattr(test, "suite"):
+    try:
       suite = strclass(test.suite)
       suite_location = test.suite.location
       location = test.suite.abs_location
@@ -160,7 +160,7 @@ class TeamcityTestResult(TestResult):
         location = location + ":" + str(test.lineno)
       else:
         location = location + ":" + str(test.test.lineno)
-    else:
+    except AttributeError:
       import inspect
 
       try:
diff --git a/python/testData/testRunner/env/unit/test_load_protocol.py b/python/testData/testRunner/env/unit/test_load_protocol.py
new file mode 100644 (file)
index 0000000..d82be81
--- /dev/null
@@ -0,0 +1,38 @@
+# Checks Load test protocol for unittest
+import unittest
+
+
+class ParametricTestCase(unittest.TestCase):
+
+    def __init__(self, method="run_test", p=0):
+        super(ParametricTestCase, self).__init__(method)
+        self.p = p
+
+    def run_test(self):
+        self.assertGreater(self.p, 0)
+
+    def __str__(self):
+        return "ParametricTestCase(p={0.p})".format(self)
+
+    @staticmethod
+    def suite():
+
+        return unittest.TestSuite([
+
+            ParametricTestCase(p=1),
+            ParametricTestCase(p=2),
+            ParametricTestCase(p=3)
+
+        ])
+
+
+def load_tests(loader, tests, pattern):
+
+    suite = ParametricTestCase.suite()
+    tests.addTests(suite)
+
+    return tests
+
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
index 33b89821ce19d81b3437506a81974aabde360d0b..a5a2475b698544a42366f85078f1f02ee397dcae 100644 (file)
@@ -13,7 +13,7 @@ import java.util.List;
 /**
  * @author traff
  */
-public class PythonUnitTestingTest extends PyEnvTestCase {
+public final class PythonUnitTestingTest extends PyEnvTestCase {
   public void testUTRunner() {
     runPythonTest(new PyUnitTestProcessWithConsoleTestTask("/testRunner/env/unit", "test1.py") {
 
@@ -30,6 +30,22 @@ public class PythonUnitTestingTest extends PyEnvTestCase {
     });
   }
 
+  /**
+   * Checks <a href="https://docs.python.org/2/library/unittest.html#load-tests-protocol">Load test protocol</a>
+   */
+  public void testLoadProtocol() throws Exception {
+    runPythonTest(new PyUnitTestProcessWithConsoleTestTask("/testRunner/env/unit", "test_load_protocol.py") {
+      @Override
+      protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
+                                      @NotNull final String stdout,
+                                      @NotNull final String stderr,
+                                      @NotNull final String all) {
+        Assert.assertEquals("bad num of passed tests: unittest load protocol failed to find tests?", 3, runner.getPassedTestsCount());
+        runner.assertAllTestsPassed();
+      }
+    });
+  }
+
   /**
    * Ensures that skipped and erroneous tests do not lead to suite ignorance
    */