testhide-pytest-plugin 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 thuesdays
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: testhide-pytest-plugin
3
+ Version: 0.1.0
4
+ Summary: A pytest plugin for creating incremental XML test reports for Testhide system.
5
+ Author-email: Mykola Kovhanko <thuesdays@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 thuesdays
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/thuesdays/testhide-pytest-plugin
28
+ Project-URL: Bug Tracker, https://github.com/thuesdays/testhide-pytest-plugin/issues
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Framework :: Pytest
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: pytest>=7.0
37
+ Dynamic: license-file
38
+
39
+ # Testhide Pytest Plugin
40
+
41
+ A pytest plugin for creating incremental XML test reports. This plugin is designed to be extensible, allowing other plugins to inject metadata and test attachments.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install testhide-pytest-plugin
@@ -0,0 +1,8 @@
1
+ # Testhide Pytest Plugin
2
+
3
+ A pytest plugin for creating incremental XML test reports. This plugin is designed to be extensible, allowing other plugins to inject metadata and test attachments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install testhide-pytest-plugin
@@ -0,0 +1,32 @@
1
+ # pyproject.toml
2
+
3
+ [build-system]
4
+ requires = ["setuptools>=61.0"]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [project]
8
+ name = "testhide-pytest-plugin"
9
+ version = "0.1.0"
10
+ authors = [
11
+ { name="Mykola Kovhanko", email="thuesdays@gmail.com" },
12
+ ]
13
+ description = "A pytest plugin for creating incremental XML test reports for Testhide system."
14
+ readme = "README.md"
15
+ license = { file="LICENSE" }
16
+ requires-python = ">=3.8"
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ "Framework :: Pytest",
22
+ ]
23
+ dependencies = [
24
+ "pytest>=7.0",
25
+ ]
26
+
27
+ [project.urls]
28
+ "Homepage" = "https://github.com/thuesdays/testhide-pytest-plugin"
29
+ "Bug Tracker" = "https://github.com/thuesdays/testhide-pytest-plugin/issues"
30
+
31
+ [project.entry-points."pytest11"]
32
+ testhide_plugin = "testhide_plugin.plugin"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,174 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ __author__ = 'thuesdays@gmail.com'
4
+
5
+ import sys
6
+ import socket
7
+ import xml.etree.ElementTree as ET
8
+ from datetime import datetime
9
+
10
+ import pytest
11
+ from pytest import hookspec
12
+
13
+
14
+ # --- Custom Hooks Specifications ---
15
+ @hookspec
16
+ def pytest_testhide_add_session_properties(plugin):
17
+ """
18
+ Hook for adding session-level metadata properties to the report.
19
+ These are added at the end of the <testsuites> block.
20
+ Should return a list of (name, value) tuples.
21
+ """
22
+
23
+
24
+ @hookspec
25
+ def pytest_testhide_get_test_case_properties(item, report) -> list:
26
+ """
27
+ Hook for getting per-test-case properties (docstr, info, attachments).
28
+ These are added inside the <testcase>'s own <properties> block.
29
+ Should return a list of (name, value) tuples.
30
+ """
31
+
32
+
33
+ class TesthidePlugin:
34
+ """
35
+ A pytest plugin to create an incremental XML report with a structure
36
+ matching the provided example.
37
+ """
38
+
39
+ def __init__(self, config):
40
+ self.config = config
41
+ self.report_xml_path = config.option.report_xml
42
+ self.xml_report_root = None
43
+ self.xml_main_testsuite = None
44
+ self.test_reports = {}
45
+
46
+ def _write_xml_report(self):
47
+ """Writes the current XML tree to the report file."""
48
+ if self.xml_report_root is None or not self.report_xml_path: return
49
+ try:
50
+ tree = ET.ElementTree(self.xml_report_root)
51
+ ET.indent(tree, space="\t", level=0) # Using tabs to match example
52
+ tree.write(self.report_xml_path, encoding='utf-8', xml_declaration=True)
53
+ except Exception as e:
54
+ self.config.warn('TESHIDE_PLUGIN_ERROR', f"TesthidePlugin failed to write XML report: {e}")
55
+
56
+ # --- Pytest Hooks Implementation ---
57
+
58
+ def pytest_sessionstart(self, session):
59
+ """Initializes the main report structure at the start."""
60
+ self.xml_report_root = ET.Element('testsuites')
61
+ self.xml_main_testsuite = ET.SubElement(
62
+ self.xml_report_root, 'testsuite',
63
+ name='pytest', # As per example
64
+ timestamp=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3],
65
+ hostname=socket.gethostname()
66
+ )
67
+ # Session properties are now added at the end in pytest_sessionfinish
68
+
69
+ def pytest_runtest_logreport(self, report):
70
+ """Captures the test result object."""
71
+ if report.when == 'call' or (report.when == 'setup' and report.failed):
72
+ self.test_reports[report.nodeid] = report
73
+
74
+ def pytest_runtest_teardown(self, item):
75
+ """Adds the completed test case to the XML report."""
76
+ if item.nodeid not in self.test_reports: return
77
+ report = self.test_reports[item.nodeid]
78
+
79
+ # Get all necessary attributes for <testcase>
80
+ classname = f"{item.module.__name__}.{item.cls.__name__}" if item.cls else item.module.__name__
81
+ filepath = item.location[0]
82
+ line = str(item.location[1])
83
+
84
+ testcase_attrs = {
85
+ 'classname': classname,
86
+ 'name': item.name,
87
+ 'file': filepath,
88
+ 'line': line,
89
+ 'time': f"{report.duration:.3f}"
90
+ }
91
+ testcase = ET.Element('testcase', **testcase_attrs)
92
+
93
+ # Add failure/skipped tags if necessary
94
+ if report.failed:
95
+ tag = 'error' if report.when == 'setup' else 'failure'
96
+ failure_element = ET.SubElement(testcase, tag, message=str(report.longrepr.reprcrash))
97
+ failure_element.text = str(report.longrepr)
98
+ elif report.skipped:
99
+ skipped_attrs = {'type': 'pytest.skip', 'message': report.longrepr[2]}
100
+ ET.SubElement(testcase, 'skipped',
101
+ **skipped_attrs).text = f"{report.longrepr[0]}:{report.longrepr[1]}: {report.longrepr[2]}"
102
+
103
+ # --- Call custom hook to get per-test properties (docstr, info, attachments) ---
104
+ all_properties = self.config.hook.pytest_testhide_get_test_case_properties(item=item, report=report)
105
+ flat_properties = [prop for sublist in all_properties for prop in sublist]
106
+
107
+ if flat_properties:
108
+ properties_element = ET.SubElement(testcase, 'properties')
109
+ for name, value in flat_properties:
110
+ ET.SubElement(properties_element, 'property', name=name).text = str(value)
111
+
112
+ self.xml_main_testsuite.append(testcase)
113
+ # To ensure data is saved if the run is aborted, we write after each test.
114
+ # This has a performance cost. For very large test suites, consider
115
+ # moving this call to pytest_sessionfinish only.
116
+ self._update_suite_summary_and_write()
117
+
118
+ def _update_suite_summary_and_write(self):
119
+ """Updates the main testsuite summary attributes and writes the file."""
120
+ if self.xml_main_testsuite is None: return
121
+
122
+ testcases = self.xml_main_testsuite.findall('testcase')
123
+ self.xml_main_testsuite.set('tests', str(len(testcases)))
124
+ self.xml_main_testsuite.set('failures', str(len(self.xml_main_testsuite.findall('.//failure'))))
125
+ self.xml_main_testsuite.set('errors', str(len(self.xml_main_testsuite.findall('.//error'))))
126
+ self.xml_main_testsuite.set('skipped', str(len(self.xml_main_testsuite.findall('.//skipped'))))
127
+ total_time = sum(float(tc.get('time', 0)) for tc in testcases)
128
+ self.xml_main_testsuite.set('time', f"{total_time:.3f}")
129
+
130
+ self._write_xml_report()
131
+
132
+ def pytest_sessionfinish(self, session):
133
+ """Adds final session properties and performs the final write."""
134
+
135
+ # --- Add mandatory properties ---
136
+ session_properties = [
137
+ ('ip_address', socket.gethostbyname(socket.gethostname())),
138
+ ('hostname', socket.gethostname())
139
+ ]
140
+
141
+ # --- Call custom hook to get user-defined session properties ---
142
+ all_user_properties = self.config.hook.pytest_testhide_add_session_properties(plugin=self)
143
+ for prop_list in all_user_properties:
144
+ session_properties.extend(prop_list)
145
+
146
+ # Create the final <properties> block under <testsuites>
147
+ properties_element = ET.SubElement(self.xml_report_root, 'properties')
148
+ for name, value in session_properties:
149
+ ET.SubElement(properties_element, 'property', name=str(name), value=str(value))
150
+
151
+ # Perform the final write
152
+ self._update_suite_summary_and_write()
153
+
154
+
155
+ # --- Functions that register the plugin and its hooks with pytest ---
156
+ def pytest_addoption(parser):
157
+ group = parser.getgroup('testhide-reporting', 'Testhide Incremental Reporting')
158
+ group.addoption('--report-xml', action='store', default=None,
159
+ help='Enable incremental XML reporting to the specified file.')
160
+
161
+
162
+ def pytest_configure(config):
163
+ config.pluginmanager.add_hookspecs(sys.modules[__name__])
164
+ if config.option.report_xml:
165
+ plugin = TesthidePlugin(config)
166
+ config._testhide_plugin = plugin
167
+ config.pluginmanager.register(plugin, "testhide_plugin")
168
+
169
+
170
+ def pytest_unconfigure(config):
171
+ plugin = getattr(config, '_testhide_plugin', None)
172
+ if plugin:
173
+ del config._testhide_plugin
174
+ config.pluginmanager.unregister(plugin)
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: testhide-pytest-plugin
3
+ Version: 0.1.0
4
+ Summary: A pytest plugin for creating incremental XML test reports for Testhide system.
5
+ Author-email: Mykola Kovhanko <thuesdays@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 thuesdays
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/thuesdays/testhide-pytest-plugin
28
+ Project-URL: Bug Tracker, https://github.com/thuesdays/testhide-pytest-plugin/issues
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Framework :: Pytest
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: pytest>=7.0
37
+ Dynamic: license-file
38
+
39
+ # Testhide Pytest Plugin
40
+
41
+ A pytest plugin for creating incremental XML test reports. This plugin is designed to be extensible, allowing other plugins to inject metadata and test attachments.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install testhide-pytest-plugin
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/testhide_plugin/__init__.py
5
+ src/testhide_plugin/plugin.py
6
+ src/testhide_pytest_plugin.egg-info/PKG-INFO
7
+ src/testhide_pytest_plugin.egg-info/SOURCES.txt
8
+ src/testhide_pytest_plugin.egg-info/dependency_links.txt
9
+ src/testhide_pytest_plugin.egg-info/entry_points.txt
10
+ src/testhide_pytest_plugin.egg-info/requires.txt
11
+ src/testhide_pytest_plugin.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ testhide_plugin = testhide_plugin.plugin