eric7/Testing/TestingWidget.py

branch
unittest
changeset 9089
b48a6d0f6309
parent 9084
ee36935f4edd
child 9093
437bfe0c5793
--- a/eric7/Testing/TestingWidget.py	Fri May 20 11:31:18 2022 +0200
+++ b/eric7/Testing/TestingWidget.py	Mon May 23 16:48:19 2022 +0200
@@ -158,6 +158,7 @@
                 self.__populateVenvComboBox)
             self.__venvManager.virtualEnvironmentChanged.connect(
                 self.__populateVenvComboBox)
+            ericApp().registerObject("VirtualEnvManager", self.__venvManager)
             
             self.__project = None
         
@@ -175,8 +176,6 @@
         self.__testExecutor = None
         
         # connect some signals
-        self.frameworkComboBox.currentIndexChanged.connect(
-            self.__resetResults)
         self.discoveryPicker.editTextChanged.connect(
             self.__resetResults)
         self.testsuitePicker.editTextChanged.connect(
@@ -330,6 +329,9 @@
         
         self.discoverCheckBox.setChecked(forProject or not bool(testFile))
         
+        if forProject:
+            self.__projectOpened()
+        
         self.tabWidget.setCurrentIndex(0)
     
     @pyqtSlot(str)
@@ -495,11 +497,11 @@
         self.__showCoverageButton.setEnabled(
             self.__mode == TestingWidgetModes.STOPPED and
             bool(self.__coverageFile) and
-                (
-                    (self.discoverCheckBox.isChecked() and
-                     bool(self.discoveryPicker.currentText())) or
-                    bool(self.testsuitePicker.currentText())
-                )
+            (
+                (self.discoverCheckBox.isChecked() and
+                 bool(self.discoveryPicker.currentText())) or
+                bool(self.testsuitePicker.currentText())
+            )
         )
         
         # Close button
@@ -644,6 +646,41 @@
         self.__updateButtonBoxButtons()
         
         self.versionsButton.setEnabled(bool(self.venvComboBox.currentText()))
+        
+        self.__updateCoverage()
+    
+    @pyqtSlot(int)
+    def on_frameworkComboBox_currentIndexChanged(self, index):
+        """
+        Private slot handling the selection of a test framework.
+        
+        @param index index of the selected framework
+        @type int
+        """
+        self.__resetResults()
+        self.__updateCoverage()
+    
+    @pyqtSlot()
+    def __updateCoverage(self):
+        """
+        Private slot to update the state of the coverage checkbox depending on
+        the selected framework's capabilities.
+        """
+        hasCoverage = False
+        
+        venvName = self.venvComboBox.currentText()
+        if venvName:
+            framework = self.frameworkComboBox.currentText()
+            if framework:
+                interpreter = self.__venvManager.getVirtualenvInterpreter(
+                    venvName)
+                executor = self.__frameworkRegistry.createExecutor(
+                    framework, self)
+                hasCoverage = executor.hasCoverage(interpreter)
+        
+        self.coverageCheckBox.setEnabled(hasCoverage)
+        if not hasCoverage:
+            self.coverageCheckBox.setChecked(False)
     
     @pyqtSlot()
     def on_versionsButton_clicked(self):
@@ -723,8 +760,6 @@
             testName = self.testComboBox.currentText()
             if testName:
                 self.__insertTestName(testName)
-            if testFileName and not testName:
-                testName = "suite"
         
         self.sbLabel.setText(self.tr("Preparing Testsuite"))
         QCoreApplication.processEvents()
@@ -781,9 +816,9 @@
         """
         Private slot handling the 'collected' signal of the executor.
         
-        @param testNames list of tuples containing the test id and test name
-            of collected tests
-        @type list of tuple of (str, str)
+        @param testNames list of tuples containing the test id, the test name
+            and a description of collected tests
+        @type list of tuple of (str, str, str)
         """
         testResults = [
             TestResult(
@@ -794,9 +829,9 @@
                 message=desc,
             ) for id, name, desc in testNames
         ]
-        self.__resultsModel.setTestResults(testResults)
+        self.__resultsModel.addTestResults(testResults)
         
-        self.__totalCount = len(testResults)
+        self.__totalCount += len(testResults)
         self.__updateProgress()
     
     @pyqtSlot(list)
@@ -879,6 +914,8 @@
         """
         self.__setStoppedMode()
         self.__testExecutor = None
+        
+        self.__adjustPendingState()
     
     @pyqtSlot(int, float)
     def __testRunFinished(self, noTests, duration):
@@ -915,6 +952,21 @@
         """
         self.__resultsModel.clear()
     
+    def __adjustPendingState(self):
+        """
+        Private method to change the status indicator of all still pending
+        tests to "not run".
+        """
+        newResults = []
+        for result in self.__resultsModel.getTestResults():
+            if result.category == TestResultCategory.PENDING:
+                result.category = TestResultCategory.SKIP
+                result.status = self.tr("not run")
+                newResults.append(result)
+        
+        if newResults:
+            self.__resultsModel.updateTestResults(newResults)
+    
     @pyqtSlot(str)
     def __coverageData(self, coverageFile):
         """
@@ -936,10 +988,11 @@
             self.__coverageDialog = PyCoverageDialog(self)
             self.__coverageDialog.openFile.connect(self.__openEditor)
         
-        if self.discoverCheckBox.isChecked():
-            testDir = self.discoveryPicker.currentText()
-        else:
-            testDir = os.path.dirname(self.testsuitePicker.currentText())
+        testDir = (
+            self.discoveryPicker.currentText()
+            if self.discoverCheckBox.isChecked() else
+            os.path.dirname(self.testsuitePicker.currentText())
+        )
         if testDir:
             self.__coverageDialog.show()
             self.__coverageDialog.start(self.__coverageFile, testDir)

eric ide

mercurial