src/eric7/Testing/Interfaces/UnittestExecutor.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10079
0222a480e93d
parent 10439
21c28b0f9e41
child 10694
f46c1e224e8a
equal deleted inserted replaced
10366:411df92e881f 10460:3b34efa2857c
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2022 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2022 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the executor for the standard 'unittest' framework. 7 Module implementing the executor for the standard 'unittest' framework.
8 """ 8 """
80 80
81 return {} 81 return {}
82 82
83 def hasCoverage(self, interpreter): # noqa: U100 83 def hasCoverage(self, interpreter): # noqa: U100
84 """ 84 """
85 Public method to get the test framework version and version information 85 Public method to check, if the collection of coverage data is available.
86 of its installed plugins.
87 86
88 @param interpreter interpreter to be used for the test 87 @param interpreter interpreter to be used for the test
89 @type str 88 @type str
90 @return flag indicating the availability of coverage functionality 89 @return flag indicating the availability of coverage functionality
91 @rtype bool 90 @rtype bool
92 """ 91 """
93 return True 92 proc = QProcess()
93 proc.start(interpreter, [UnittestExecutor.runner, "has_coverage"])
94 if proc.waitForFinished(3000):
95 return proc.exitCode() == 0
96
97 return False
94 98
95 def supportsPatterns(self, interpreter): # noqa: U100 99 def supportsPatterns(self, interpreter): # noqa: U100
96 """ 100 """
97 Public method to indicate the support for test filtering using test name 101 Public method to indicate the support for test filtering using test name
98 patterns or a test name pattern expression. 102 patterns or a test name pattern expression.
113 @return list of process arguments 117 @return list of process arguments
114 @rtype list of str 118 @rtype list of str
115 """ 119 """
116 args = [ 120 args = [
117 UnittestExecutor.runner, 121 UnittestExecutor.runner,
118 "runtest", 122 "discovery" if config.discoverOnly else "runtest",
119 self.reader.address(), 123 self.reader.address(),
120 str(self.reader.port()), 124 str(self.reader.port()),
121 ] 125 ]
122 126
123 if config.discover: 127 if config.discover:
147 if config.failedOnly: 151 if config.failedOnly:
148 args.append("--failed-only") 152 args.append("--failed-only")
149 if config.testFilename: 153 if config.testFilename:
150 args.append(config.testFilename) 154 args.append(config.testFilename)
151 args.extend(self.__testWidget.getFailedTests()) 155 args.extend(self.__testWidget.getFailedTests())
156 elif config.testCases:
157 args.extend(config.testCases)
152 elif config.testFilename: 158 elif config.testFilename:
153 args.append(config.testFilename) 159 args.append(config.testFilename)
154 args.append(config.testName if config.testName else "@NONE@") 160 args.append(config.testName if config.testName else "@NONE@")
155 # @NONE@ is just a marker for no test name given 161 # @NONE@ is just a marker for no test name given
156 162
157 return args 163 return args
158 164
165 def discover(self, config, pythonpath):
166 """
167 Public method to start the test discovery process.
168
169 @param config configuration for the test discovery
170 @type TestConfig
171 @param pythonpath list of directories to be added to the Python path
172 @type list of str
173 """
174 self.reader = EricJsonReader(name="Unittest Reader", parent=self)
175 self.reader.dataReceived.connect(self.__processData)
176
177 super().discover(config, pythonpath)
178
159 def start(self, config, pythonpath): 179 def start(self, config, pythonpath):
160 """ 180 """
161 Public method to start the testing process. 181 Public method to start the testing process.
162 182
163 @param config configuration for the test execution 183 @param config configuration for the test execution
168 self.reader = EricJsonReader(name="Unittest Reader", parent=self) 188 self.reader = EricJsonReader(name="Unittest Reader", parent=self)
169 self.reader.dataReceived.connect(self.__processData) 189 self.reader.dataReceived.connect(self.__processData)
170 190
171 super().start(config, pythonpath) 191 super().start(config, pythonpath)
172 192
193 def startDebug(self, config, pythonpath, debugger):
194 """
195 Public method to start the test run with debugger support.
196
197 @param config configuration for the test execution
198 @type TestConfig
199 @param pythonpath list of directories to be added to the Python path
200 @type list of str
201 @param debugger refference to the debugger interface
202 @type DebugUI
203 """
204 self.reader = EricJsonReader(name="Unittest Reader", parent=self)
205 self.reader.dataReceived.connect(self.__processData)
206
207 super().startDebug(config, pythonpath, debugger)
208
173 def finished(self): 209 def finished(self):
174 """ 210 """
175 Public method handling the unit test process been finished. 211 Public method handling the unit test process been finished.
176 212
177 This method should read the results (if necessary) and emit the signal 213 This method should read the results (if necessary) and emit the signal
179 """ 215 """
180 self.reader.close() 216 self.reader.close()
181 217
182 output = self.readAllOutput() 218 output = self.readAllOutput()
183 self.testFinished.emit([], output) 219 self.testFinished.emit([], output)
220
221 super().finished()
184 222
185 @pyqtSlot(object) 223 @pyqtSlot(object)
186 def __processData(self, data): 224 def __processData(self, data):
187 """ 225 """
188 Private slot to process the received data. 226 Private slot to process the received data.
195 self.collectError.emit([("", data["error"])]) 233 self.collectError.emit([("", data["error"])])
196 234
197 # tests collected 235 # tests collected
198 elif data["event"] == "collected": 236 elif data["event"] == "collected":
199 self.collected.emit( 237 self.collected.emit(
200 [(t["id"], t["name"], t["description"]) for t in data["tests"]] 238 [
239 (
240 t["id"],
241 t["name"],
242 t["description"],
243 t["filename"],
244 0,
245 t["id"].split("."),
246 )
247 for t in data["tests"]
248 ]
201 ) 249 )
202 250
203 # test started 251 # test started
204 elif data["event"] == "started": 252 elif data["event"] == "started":
205 self.startTest.emit((data["id"], data["name"], data["description"])) 253 self.startTest.emit((data["id"], data["name"], data["description"]))

eric ide

mercurial