PyUnit: added support for sub-tests. eric7

Wed, 25 Aug 2021 17:33:29 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Aug 2021 17:33:29 +0200
branch
eric7
changeset 8542
f8d3b4511358
parent 8541
927d57b6aae0
child 8545
9c9779b7142a

PyUnit: added support for sub-tests.

eric7/DebugClients/Python/DCTestResult.py file | annotate | diff | comparison | revisions
eric7/PyUnit/UnittestDialog.py file | annotate | diff | comparison | revisions
--- a/eric7/DebugClients/Python/DCTestResult.py	Tue Aug 24 18:10:24 2021 +0200
+++ b/eric7/DebugClients/Python/DCTestResult.py	Wed Aug 25 17:33:29 2021 +0200
@@ -29,7 +29,7 @@
         TestResult.__init__(self)
         self.__dbgClient = dbgClient
         self.failfast = failfast
-        
+    
     def addFailure(self, test, err):
         """
         Public method called if a test failed.
@@ -44,7 +44,7 @@
             "traceback": tracebackLines,
             "id": test.id(),
         })
-        
+    
     def addError(self, test, err):
         """
         Public method called if a test errored.
@@ -59,7 +59,31 @@
             "traceback": tracebackLines,
             "id": test.id(),
         })
+    
+    def addSubTest(self, test, subtest, err):
+        """
+        Public method called for each subtest to record its result.
         
+        @param test reference to the test object
+        @param subtest reference to the subtest object
+        @param err error traceback
+        """
+        if err is not None:
+            TestResult.addSubTest(self, test, subtest, err)
+            tracebackLines = self._exc_info_to_string(err, test)
+            if issubclass(err[0], test.failureException):
+                self.__dbgClient.sendJsonCommand("ResponseUTTestFailed", {
+                    "testname": str(subtest),
+                    "traceback": tracebackLines,
+                    "id": test.id(),
+                })
+            else:
+                self.__dbgClient.sendJsonCommand("ResponseUTTestErrored", {
+                    "testname": str(subtest),
+                    "traceback": tracebackLines,
+                    "id": test.id(),
+                })
+    
     def addSkip(self, test, reason):
         """
         Public method called if a test was skipped.
@@ -73,7 +97,7 @@
             "reason": reason,
             "id": test.id(),
         })
-        
+    
     def addExpectedFailure(self, test, err):
         """
         Public method called if a test failed expected.
@@ -88,7 +112,7 @@
             "traceback": tracebackLines,
             "id": test.id(),
         })
-        
+    
     def addUnexpectedSuccess(self, test):
         """
         Public method called if a test succeeded expectedly.
@@ -100,7 +124,7 @@
             "testname": str(test),
             "id": test.id(),
         })
-        
+    
     def startTest(self, test):
         """
         Public method called at the start of a test.
@@ -112,7 +136,7 @@
             "testname": str(test),
             "description": test.shortDescription(),
         })
-
+    
     def stopTest(self, test):
         """
         Public method called at the end of a test.
--- a/eric7/PyUnit/UnittestDialog.py	Tue Aug 24 18:10:24 2021 +0200
+++ b/eric7/PyUnit/UnittestDialog.py	Wed Aug 25 17:33:29 2021 +0200
@@ -174,7 +174,7 @@
             "^Error: ",
         ]
         
-        self.__failedTests = []
+        self.__failedTests = set()
         
         # now connect the debug server signals if called from the eric IDE
         if self.__dbs:
@@ -766,13 +766,13 @@
                     clientType = "Python3"
                 sysPath = []
             if failedOnly and self.__failedTests:
-                failed = self.__failedTests[:]
+                failed = list(self.__failedTests)
                 if discover:
                     workdir = discoveryStart
                     discover = False
             else:
                 failed = []
-            self.__failedTests = []
+            self.__failedTests = set()
             self.__dbs.remoteUTPrepare(
                 testFileName, self.testName, testName, failed,
                 self.coverageCheckBox.isChecked(), coverageFile,
@@ -817,7 +817,7 @@
             try:
                 testLoader = unittest.TestLoader()
                 if failedOnly and self.__failedTests:
-                    failed = self.__failedTests[:]
+                    failed = list(self.__failedTests)
                     if discover:
                         os.chdir(discoveryStart)
                         discover = False
@@ -838,7 +838,7 @@
                             failed = [t.split(".", 1)[1]
                                       for t in self.__failedTests]
                         else:
-                            failed = self.__failedTests[:]
+                            failed = list(self.__failedTests)
                         test = testLoader.loadTestsFromNames(
                             failed, module)
                     else:
@@ -883,7 +883,7 @@
                     self.tr("Unittest"),
                     self.tr("""No unittest were found. Aborting..."""))
             else:
-                self.__failedTests = []
+                self.__failedTests = set()
                 self.__setRunningMode()
                 if cover:
                     cover.start()
@@ -1035,7 +1035,7 @@
         itm = QListWidgetItem(self.tr("Failure: {0}").format(test))
         itm.setData(UnittestDialog.ErrorsInfoRole, (test, exc))
         self.errorsListWidget.insertItem(0, itm)
-        self.__failedTests.append(testId)
+        self.__failedTests.add(testId)
     
     def testErrored(self, test, exc, testId):
         """
@@ -1050,7 +1050,7 @@
         itm = QListWidgetItem(self.tr("Error: {0}").format(test))
         itm.setData(UnittestDialog.ErrorsInfoRole, (test, exc))
         self.errorsListWidget.insertItem(0, itm)
-        self.__failedTests.append(testId)
+        self.__failedTests.add(testId)
     
     def testSkipped(self, test, reason, testId):
         """
@@ -1278,6 +1278,24 @@
         tracebackLines = self._exc_info_to_string(err, test)
         self.parent.testErrored(str(test), tracebackLines, test.id())
     
+    def addSubTest(self, test, subtest, err):
+        """
+        Public method called for each subtest to record its result.
+        
+        @param test reference to the test object
+        @param subtest reference to the subtest object
+        @param err error traceback
+        """
+        if err is not None:
+            super().addSubTest(test, subtest, err)
+            tracebackLines = self._exc_info_to_string(err, test)
+            if issubclass(err[0], test.failureException):
+                self.parent.testFailed(
+                    str(subtest), tracebackLines, test.id())
+            else:
+                self.parent.testErrored(
+                    str(subtest), tracebackLines, test.id())
+    
     def addSkip(self, test, reason):
         """
         Public method called if a test was skipped.

eric ide

mercurial