src/eric7/Testing/Interfaces/TestExecutorBase.py

branch
eric7
changeset 10405
df7e1694d0eb
parent 10404
f7d9c31f0c38
child 10415
af9a6dac2611
equal deleted inserted replaced
10404:f7d9c31f0c38 10405:df7e1694d0eb
8 and supporting classes. 8 and supporting classes.
9 """ 9 """
10 10
11 import os 11 import os
12 12
13 from dataclasses import dataclass 13 from dataclasses import dataclass, field
14 from enum import IntEnum 14 from enum import IntEnum
15 15
16 from PyQt6.QtCore import QObject, QProcess, QProcessEnvironment, pyqtSignal 16 from PyQt6.QtCore import QObject, QProcess, QProcessEnvironment, pyqtSignal
17 17
18 from eric7 import Preferences 18 from eric7 import Preferences
54 """ 54 """
55 Class containing the test run configuration. 55 Class containing the test run configuration.
56 """ 56 """
57 57
58 interpreter: str # path of the Python interpreter 58 interpreter: str # path of the Python interpreter
59 discover: bool # auto discovery flag 59 discover: bool = False # auto discovery flag
60 discoveryStart: str # start directory for auto discovery 60 discoveryStart: str = "" # start directory for auto discovery
61 testFilename: str # name of the test script 61 testCases: list = field(default_factory=list) # list of selected test cases
62 testName: str # name of the test function 62 testFilename: str = "" # name of the test script
63 testMarkerExpression: str # marker expression for test selection 63 testName: str = "" # name of the test function
64 testNamePattern: str # test name pattern expression or list 64 testMarkerExpression: str = "" # marker expression for test selection
65 failFast: bool # stop on first fail 65 testNamePattern: str = "" # test name pattern expression or list
66 failedOnly: bool # run failed tests only 66 failFast: bool = False # stop on first fail
67 collectCoverage: bool # coverage collection flag 67 failedOnly: bool = False # run failed tests only
68 eraseCoverage: bool # erase coverage data first 68 collectCoverage: bool = False # coverage collection flag
69 coverageFile: str # name of the coverage data file 69 eraseCoverage: bool = False # erase coverage data first
70 coverageFile: str = "" # name of the coverage data file
71 discoverOnly: bool = False # test discovery only
70 72
71 73
72 class TestExecutorBase(QObject): 74 class TestExecutorBase(QObject):
73 """ 75 """
74 Base class for test framework specific implementations. 76 Base class for test framework specific implementations.
75 77
76 @signal collected(list of tuple of (str, str, str, str, int)) emitted after all 78 @signal collected(list of tuple of (str, str, str, str, int, list)) emitted after
77 tests have been collected. Tuple elements are the test id, the test name, 79 all tests have been collected. Tuple elements are the test id, the test name,
78 a short description of the test, the test file name and the line number of 80 a short description of the test, the test file name, the line number of
79 the test. 81 the test and the elements of the test path as a list.
80 @signal collectError(list of tuple of (str, str)) emitted when errors 82 @signal collectError(list of tuple of (str, str)) emitted when errors
81 are encountered during test collection. Tuple elements are the 83 are encountered during test collection. Tuple elements are the
82 test name and the error message. 84 test name and the error message.
83 @signal startTest(tuple of (str, str, str) emitted before tests are run. 85 @signal startTest(tuple of (str, str, str) emitted before tests are run.
84 Tuple elements are test id, test name and short description. 86 Tuple elements are test id, test name and short description.
87 The elements are the list of test results and the captured output 89 The elements are the list of test results and the captured output
88 of the test worker (if any). 90 of the test worker (if any).
89 @signal testRunAboutToBeStarted() emitted just before the test run will 91 @signal testRunAboutToBeStarted() emitted just before the test run will
90 be started. 92 be started.
91 @signal testRunFinished(int, float) emitted when the test run has finished. 93 @signal testRunFinished(int, float) emitted when the test run has finished.
92 The elements are the number of tests run and the duration in seconds 94 The elements are the number of tests run and the duration in seconds.
93 @signal stop() emitted when the test process is being stopped. 95 @signal stop() emitted when the test process is being stopped.
94 @signal coverageDataSaved(str) emitted after the coverage data was saved. 96 @signal coverageDataSaved(str) emitted after the coverage data was saved.
95 The element is the absolute path of the coverage data file. 97 The element is the absolute path of the coverage data file.
98 @signal discoveryAboutToBeStarted() emitted just before the test discovery
99 will be started
100 @signal discoveryFinished(int, float) emitted when the discovery has finished.
101 The elements are the number of discovered tests and the duration in seconds.
96 """ 102 """
97 103
98 collected = pyqtSignal(list) 104 collected = pyqtSignal(list)
99 collectError = pyqtSignal(list) 105 collectError = pyqtSignal(list)
100 startTest = pyqtSignal(tuple) 106 startTest = pyqtSignal(tuple)
102 testFinished = pyqtSignal(list, str) 108 testFinished = pyqtSignal(list, str)
103 testRunAboutToBeStarted = pyqtSignal() 109 testRunAboutToBeStarted = pyqtSignal()
104 testRunFinished = pyqtSignal(int, float) 110 testRunFinished = pyqtSignal(int, float)
105 stop = pyqtSignal() 111 stop = pyqtSignal()
106 coverageDataSaved = pyqtSignal(str) 112 coverageDataSaved = pyqtSignal(str)
113 discoveryAboutToBeStarted = pyqtSignal()
114 discoveryFinished = pyqtSignal(int, float)
107 115
108 module = "" 116 module = ""
109 name = "" 117 name = ""
110 runner = "" 118 runner = ""
111 119
243 env.insert("PYTHONPATH", newPythonPath) 251 env.insert("PYTHONPATH", newPythonPath)
244 process.setProcessEnvironment(env) 252 process.setProcessEnvironment(env)
245 253
246 return process 254 return process
247 255
256 def discover(self, config, pythonpath):
257 """
258 Public method to start the test discovery process.
259
260 @param config configuration for the test discovery
261 @type TestConfig
262 @param pythonpath list of directories to be added to the Python path
263 @type list of str
264 @exception RuntimeError raised if the the test discovery process did not start
265 @exception ValueError raised if no start directory for the test discovery was
266 given
267 """
268 if not config.discoveryStart:
269 raise ValueError("No discovery start directory given.")
270
271 self.__process = self._prepareProcess(config.discoveryStart, pythonpath)
272 discoveryArgs = self.createArguments(config)
273 self.discoveryAboutToBeStarted.emit()
274 self.__process.start(config.interpreter, discoveryArgs)
275 running = self.__process.waitForStarted()
276 if not running:
277 raise RuntimeError("Test discovery process did not start.")
278
248 def start(self, config, pythonpath): 279 def start(self, config, pythonpath):
249 """ 280 """
250 Public method to start the testing process. 281 Public method to start the testing process.
251 282
252 @param config configuration for the test execution 283 @param config configuration for the test execution

eric ide

mercurial