src/eric7/Testing/Interfaces/PytestExecutor.py

branch
eric7
changeset 10405
df7e1694d0eb
parent 10404
f7d9c31f0c38
child 10415
af9a6dac2611
--- a/src/eric7/Testing/Interfaces/PytestExecutor.py	Tue Dec 12 16:43:51 2023 +0100
+++ b/src/eric7/Testing/Interfaces/PytestExecutor.py	Wed Dec 13 15:54:55 2023 +0100
@@ -167,7 +167,7 @@
         else:
             args.append("--cache-clear")
 
-        if config.collectCoverage:
+        if not config.discoverOnly and config.collectCoverage:
             args.extend(["--cov=.", "--cov-report="])
             if not config.eraseCoverage:
                 args.append("--cov-append")
@@ -179,10 +179,13 @@
         if config.testNamePattern:
             args.append("-k")
             args.append(config.testNamePattern)
-##
-        ##args.append("--collect-only")
+
+        if config.discoverOnly:
+            args.append("--collect-only")
 
-        if config.testFilename:
+        if config.testCases:
+            args.extend(config.testCases)
+        elif config.testFilename:
             if config.testName:
                 args.append(
                     "{0}::{1}".format(
@@ -194,6 +197,25 @@
 
         return args
 
+    def discover(self, config, pythonpath):
+        """
+        Public method to start the test discovery process.
+
+        @param config configuration for the test discovery
+        @type TestConfig
+        @param pythonpath list of directories to be added to the Python path
+        @type list of str
+        """
+        self.reader = EricJsonReader(name="Pytest Reader", parent=self)
+        self.reader.dataReceived.connect(self.__processData)
+
+        self.__config = config
+
+        pythonpath.insert(0, os.path.abspath(config.discoveryStart))
+        self.__rootdir = config.discoveryStart
+
+        super().discover(config, pythonpath)
+
     def start(self, config, pythonpath):
         """
         Public method to start the testing process.
@@ -264,8 +286,9 @@
                         data["nodeid"],
                         self.__nodeid2testname(data["nodeid"]),
                         "",
-                        data["filename"],
+                        os.path.join(self.__rootdir, data["filename"]),
                         data["linenumber"],
+                        self.__nodeid2testpath(data["nodeid"]),
                     )
                 ]
             )
@@ -370,3 +393,17 @@
         name = name.replace("::", ".")
         testname, name = "{0}.{1}".format(module, name).rsplit(".", 1)
         return "{0} ({1})".format(name, testname)
+
+    def __nodeid2testpath(self, nodeid):
+        """
+        Private method to convert a nodeid to a test path list.
+
+        @param nodeid nodeid to be converted
+        @type str
+        @return test path list
+        @rtype list of str
+        """
+        module, name = nodeid.split("::", 1)
+        module = self.__normalizeModuleName(module)
+        name = "{0}.{1}".format(module, name.replace("::", "."))
+        return name.split(".")

eric ide

mercurial