Thu, 20 May 2021 18:08:02 +0200
Unittest: fixed a few issues related to loading unit test modules.
(grafted from e22ce9001905ae927c0706ffb8df5a73fcbf848b)
eric7/DebugClients/Python/DebugClientBase.py | file | annotate | diff | comparison | revisions | |
eric7/PyUnit/UnittestDialog.py | file | annotate | diff | comparison | revisions |
--- a/eric7/DebugClients/Python/DebugClientBase.py Thu May 20 18:20:56 2021 +0200 +++ b/eric7/DebugClients/Python/DebugClientBase.py Thu May 20 18:08:02 2021 +0200 @@ -20,7 +20,6 @@ import signal import time import types -import importlib.util import fnmatch import contextlib @@ -870,9 +869,7 @@ os.path.dirname(os.path.abspath(params["filename"])) ) if params["filename"]: - spec = importlib.util.spec_from_file_location( - params["testname"], params["filename"]) - utModule = importlib.util.module_from_spec(spec) + utModule = __import__(params["testname"]) else: utModule = None if params["failed"]:
--- a/eric7/PyUnit/UnittestDialog.py Thu May 20 18:20:56 2021 +0200 +++ b/eric7/PyUnit/UnittestDialog.py Thu May 20 18:08:02 2021 +0200 @@ -581,27 +581,25 @@ selectedTests = [] if parent is None: # top level - for index in range(self.discoveryList.topLevelItemCount()): - itm = self.discoveryList.topLevelItem(index) - if itm.checkState(0) == Qt.CheckState.Checked: - selectedTests.append( - itm.data(0, UnittestDialog.TestCaseNameRole)) - # ignore children because they are included implicitly - elif itm.childCount(): - # recursively check children - selectedTests.extend(self.__selectedTestCases(itm)) - + itemsList = [ + self.discoveryList.topLevelItem(index) + for index in range(self.discoveryList.topLevelItemCount()) + ] else: - # parent item with children - for index in range(parent.childCount()): - itm = parent.child(index) - if itm.checkState(0) == Qt.CheckState.Checked: - selectedTests.append( - itm.data(0, UnittestDialog.TestCaseNameRole)) - # ignore children because they are included implicitly - elif itm.childCount(): - # recursively check children - selectedTests.extend(self.__selectedTestCases(itm)) + itemsList = [ + parent.child(index) + for index in range(parent.childCount()) + ] + + for itm in itemsList: + if (itm.checkState(0) == Qt.CheckState.Checked and + itm.childCount() == 0 + ): + selectedTests.append( + itm.data(0, UnittestDialog.TestCaseNameRole)) + if itm.childCount(): + # recursively check children + selectedTests.extend(self.__selectedTestCases(itm)) return selectedTests @@ -882,16 +880,22 @@ self.testResult = QtTestResult( self, self.failfastCheckBox.isChecked()) self.totalTests = test.countTestCases() - self.__failedTests = [] - self.__setRunningMode() - if cover: - cover.start() - test.run(self.testResult) - if cover: - cover.stop() - cover.save() - self.__setStoppedMode() - sys.path = self.savedSysPath + if self.totalTests == 0: + E5MessageBox.warning( + self, + self.tr("Unittest"), + self.tr("""No unittest were found. Aborting...""")) + else: + self.__failedTests = [] + self.__setRunningMode() + if cover: + cover.start() + test.run(self.testResult) + if cover: + cover.stop() + cover.save() + self.__setStoppedMode() + sys.path = self.savedSysPath def __UTPrepared(self, nrTests, exc_type, exc_value): """