eric7/Unittest/Interfaces/PytestRunner.py

branch
unittest
changeset 9059
e7fd342f8bfc
child 9065
39405e6eba20
equal deleted inserted replaced
9057:ddc46e93ccc4 9059:e7fd342f8bfc
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the test runner script for the 'pytest' framework.
8 """
9
10 import json
11 import sys
12
13
14 class GetPluginVersionsPlugin():
15 """
16 Class implementing a pytest plugin to extract the version info of all
17 installed plugins.
18 """
19 def __init__(self):
20 """
21 Constructor
22 """
23 super().__init__()
24
25 self.versions = []
26
27 def pytest_cmdline_main(self, config):
28 """
29 Public method called for performing the main command line action.
30
31 @param config pytest config object
32 @type Config
33 """
34 pluginInfo = config.pluginmanager.list_plugin_distinfo()
35 if pluginInfo:
36 for _plugin, dist in pluginInfo:
37 self.versions.append({
38 "name": dist.project_name,
39 "version": dist.version
40 })
41
42 def getVersions(self):
43 """
44 Public method to get the assembled list of plugin versions.
45
46 @return list of collected plugin versions
47 @rtype list of dict
48 """
49 return self.versions
50
51
52 def getVersions():
53 """
54 Function to determine the framework version and versions of all available
55 plugins.
56 """
57 try:
58 import pytest # __IGNORE_WARNING__
59 versions = {
60 "name": "pytest",
61 "version": pytest.__version__,
62 "plugins": [],
63 }
64
65 # --capture=sys needed on Windows to avoid
66 # ValueError: saved filedescriptor not valid anymore
67 plugin = GetPluginVersionsPlugin()
68 pytest.main(['--version', '--capture=sys'], plugins=[plugin])
69 versions["plugins"] = plugin.getVersions()
70 except ImportError:
71 versions = {}
72
73 print(json.dumps(versions))
74 sys.exit(0)
75
76
77 if __name__ == '__main__':
78 command = sys.argv[1]
79 if command == "installed":
80 try:
81 import pytest # __IGNORE_WARNING__
82 sys.exit(0)
83 except ImportError:
84 sys.exit(1)
85
86 elif command == "versions":
87 getVersions()
88
89 sys.exit(42)
90
91 #
92 # eflag: noqa = M801

eric ide

mercurial