|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the executor for the 'pytest' framework. |
|
8 """ |
|
9 |
|
10 import contextlib |
|
11 import json |
|
12 import os |
|
13 |
|
14 from PyQt6.QtCore import QProcess |
|
15 |
|
16 from .UTExecutorBase import UTExecutorBase |
|
17 |
|
18 |
|
19 class PytestExecutor(UTExecutorBase): |
|
20 """ |
|
21 Class implementing the executor for the 'pytest' framework. |
|
22 """ |
|
23 module = "pytest" |
|
24 name = "pytest" |
|
25 |
|
26 runner = os.path.join(os.path.dirname(__file__), "PytestRunner.py") |
|
27 |
|
28 def getVersions(self, interpreter): |
|
29 """ |
|
30 Public method to get the test framework version and version information |
|
31 of its installed plugins. |
|
32 |
|
33 @param interpreter interpreter to be used for the test |
|
34 @type str |
|
35 @return dictionary containing the framework name and version and the |
|
36 list of available plugins with name and version each |
|
37 @rtype dict |
|
38 """ |
|
39 proc = QProcess() |
|
40 proc.start(interpreter, [PytestExecutor.runner, "versions"]) |
|
41 if proc.waitForFinished(3000): |
|
42 exitCode = proc.exitCode() |
|
43 if exitCode == 0: |
|
44 outputLines = self.readAllOutput(proc).splitlines() |
|
45 for line in outputLines: |
|
46 if line.startswith("{") and line.endswith("}"): |
|
47 with contextlib.suppress(json.JSONDecodeError): |
|
48 return json.loads(line) |
|
49 |
|
50 return {} |