eric7/Unittest/Interfaces/UnittestRunner.py

branch
unittest
changeset 9063
f1d7dd7ae471
parent 9062
7f27bf3b50c3
child 9064
339bb8c8007d
--- a/eric7/Unittest/Interfaces/UnittestRunner.py	Fri May 13 17:23:21 2022 +0200
+++ b/eric7/Unittest/Interfaces/UnittestRunner.py	Sat May 14 18:56:52 2022 +0200
@@ -77,36 +77,6 @@
             "traceback": tracebackLines,
         })
     
-    def addSubTest(self, test, subtest, err):
-        """
-        Public method called for each subtest to record its result.
-        
-        @param test reference to the test object
-        @type TestCase
-        @param subtest reference to the subtest object
-        @type TestCase
-        @param err tuple containing the exception data like sys.exc_info
-            (exception type, exception instance, traceback)
-        @type tuple
-        """
-        if err is not None:
-            super().addSubTest(test, subtest, err)
-            tracebackLines = self._exc_info_to_string(err, test)
-            status = (
-                "failure"
-                if issubclass(err[0], test.failureException) else
-                "error"
-            )
-            
-            self.__currentTestStatus.update({
-                "status": status,
-                "name": str(subtest),
-                "traceback": tracebackLines,
-            })
-            
-            if self.failfast:
-                self.stop()
-    
     def addSkip(self, test, reason):
         """
         Public method called if a test was skipped.
@@ -152,6 +122,52 @@
         
         self.__currentTestStatus["status"] = "unexpected success"
     
+    def addSubTest(self, test, subtest, err):
+        """
+        Public method called for each subtest to record its result.
+        
+        @param test reference to the test object
+        @type TestCase
+        @param subtest reference to the subtest object
+        @type TestCase
+        @param err tuple containing the exception data like sys.exc_info
+            (exception type, exception instance, traceback)
+        @type tuple
+        """
+        if err is not None:
+            super().addSubTest(test, subtest, err)
+            tracebackLines = self._exc_info_to_string(err, test)
+            status = (
+                "failure"
+                if issubclass(err[0], test.failureException) else
+                "error"
+            )
+            
+            # record the last subtest fail status as the overall status
+            self.__currentTestStatus["status"] = status
+            
+            self.__writer.write({
+                "event": "result",
+                "status": status,
+                "name": str(subtest),
+                "id": subtest.id(),
+                "description": subtest.shortDescription(),
+                "traceback": tracebackLines,
+                "subtest": True,
+            })
+            
+            if self.failfast:
+                self.stop()
+        else:
+            self.__writer.write({
+                "event": "result",
+                "status": "success",
+                "name": str(subtest),
+                "id": subtest.id(),
+                "description": subtest.shortDescription(),
+                "subtest": True,
+            })
+    
     def startTest(self, test):
         """
         Public method called at the start of a test.
@@ -168,6 +184,7 @@
             "name": str(test),
             "id": test.id(),
             "description": test.shortDescription(),
+            "subtest": False,
         }
         
         self.__writer.write({

eric ide

mercurial