pgpro-pytest-html-json-extractor 1.0.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.
- pgpro_pytest_html_json_extractor-1.0.0/LICENSE +21 -0
- pgpro_pytest_html_json_extractor-1.0.0/PKG-INFO +73 -0
- pgpro_pytest_html_json_extractor-1.0.0/README.md +45 -0
- pgpro_pytest_html_json_extractor-1.0.0/pyproject.toml +61 -0
- pgpro_pytest_html_json_extractor-1.0.0/setup.cfg +4 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor/__init__.py +1 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor/__main__.py +311 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/PKG-INFO +73 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/SOURCES.txt +11 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/dependency_links.txt +1 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/entry_points.txt +2 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/requires.txt +2 -0
- pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Postgres Professional
|
|
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,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pgpro-pytest-html-json-extractor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A tool to extract json from pytest-html report
|
|
5
|
+
Author-email: Postgres Professional <info@postgrespro.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: HomePage, https://github.com/postgrespro/pgpro-pytest-html-json-extractor
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Classifier: Framework :: Pytest
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: beautifulsoup4>=4.11.1
|
|
26
|
+
Requires-Dist: packaging>=21.0
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
[](https://github.com/postgrespro/pgpro-pytest-html-json-extractor/actions/workflows/ci.yml)
|
|
30
|
+
[](https://badge.fury.io/py/pgpro-pytest-html-json-extractor)
|
|
31
|
+
[](https://pypi.org/project/pgpro-pytest-html-json-extractor)
|
|
32
|
+
|
|
33
|
+
# pgpro-pytest-html-json-extractor
|
|
34
|
+
A tool to extract json data from pytest-html report. Developed and maintained by Postgres Professional.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
You can install the package directly from the repository (until it's published to PyPI):
|
|
38
|
+
```bash
|
|
39
|
+
pip install pgpro-pytest-html-json-extractor
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
After installation, the tool is available via the pgpro-pytest-html-json-extractor command.
|
|
45
|
+
|
|
46
|
+
### Basic Examples
|
|
47
|
+
Extract JSON from a report:
|
|
48
|
+
```bash
|
|
49
|
+
pgpro-pytest-html-json-extractor report.html -o report.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Command Line Arguments
|
|
53
|
+
|
|
54
|
+
| Argument | Shorthand | Required | Description | Default |
|
|
55
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
56
|
+
| `--version` | | No | Show program's version number and exit | None |
|
|
57
|
+
| `--out` | `-o` | Yes | Name of the output JSON file | None |
|
|
58
|
+
| `--verbose` | `-v` | No | Level of logging verbosity | 3 |
|
|
59
|
+
| `--no-check-json` | | No | Do not validate json data after extraction | None |
|
|
60
|
+
| `--replace` | `-r` | No | Replace output if it exists | None |
|
|
61
|
+
| `input` | | Yes | Positional argument for HTML file | None |
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
1. Fork the repository.
|
|
65
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`).
|
|
66
|
+
3. Commit your changes (`git commit -m 'feat: add some amazing feature'`).
|
|
67
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
68
|
+
5. Open a Pull Request.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
72
|
+
|
|
73
|
+
© 2026 Postgres Professional
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[](https://github.com/postgrespro/pgpro-pytest-html-json-extractor/actions/workflows/ci.yml)
|
|
2
|
+
[](https://badge.fury.io/py/pgpro-pytest-html-json-extractor)
|
|
3
|
+
[](https://pypi.org/project/pgpro-pytest-html-json-extractor)
|
|
4
|
+
|
|
5
|
+
# pgpro-pytest-html-json-extractor
|
|
6
|
+
A tool to extract json data from pytest-html report. Developed and maintained by Postgres Professional.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
You can install the package directly from the repository (until it's published to PyPI):
|
|
10
|
+
```bash
|
|
11
|
+
pip install pgpro-pytest-html-json-extractor
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
After installation, the tool is available via the pgpro-pytest-html-json-extractor command.
|
|
17
|
+
|
|
18
|
+
### Basic Examples
|
|
19
|
+
Extract JSON from a report:
|
|
20
|
+
```bash
|
|
21
|
+
pgpro-pytest-html-json-extractor report.html -o report.json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Command Line Arguments
|
|
25
|
+
|
|
26
|
+
| Argument | Shorthand | Required | Description | Default |
|
|
27
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
28
|
+
| `--version` | | No | Show program's version number and exit | None |
|
|
29
|
+
| `--out` | `-o` | Yes | Name of the output JSON file | None |
|
|
30
|
+
| `--verbose` | `-v` | No | Level of logging verbosity | 3 |
|
|
31
|
+
| `--no-check-json` | | No | Do not validate json data after extraction | None |
|
|
32
|
+
| `--replace` | `-r` | No | Replace output if it exists | None |
|
|
33
|
+
| `input` | | Yes | Positional argument for HTML file | None |
|
|
34
|
+
|
|
35
|
+
## Contributing
|
|
36
|
+
1. Fork the repository.
|
|
37
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`).
|
|
38
|
+
3. Commit your changes (`git commit -m 'feat: add some amazing feature'`).
|
|
39
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
40
|
+
5. Open a Pull Request.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
44
|
+
|
|
45
|
+
© 2026 Postgres Professional
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools.packages.find]
|
|
6
|
+
where = ["src"]
|
|
7
|
+
include = ["pgpro_pytest_html_json_extractor*"]
|
|
8
|
+
|
|
9
|
+
[tool.setuptools.dynamic]
|
|
10
|
+
version = {attr = "pgpro_pytest_html_json_extractor.__version__"}
|
|
11
|
+
|
|
12
|
+
[project]
|
|
13
|
+
name = "pgpro-pytest-html-json-extractor"
|
|
14
|
+
description = "A tool to extract json from pytest-html report"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
dynamic = ["version"]
|
|
18
|
+
|
|
19
|
+
authors = [
|
|
20
|
+
{name = "Postgres Professional", email = "info@postgrespro.ru"}
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
requires-python = ">=3.8"
|
|
24
|
+
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 5 - Production/Stable",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.8",
|
|
31
|
+
"Programming Language :: Python :: 3.9",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13",
|
|
36
|
+
"Programming Language :: Python :: 3.14",
|
|
37
|
+
"Topic :: Software Development :: Testing",
|
|
38
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
39
|
+
"Framework :: Pytest",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
dependencies = [
|
|
43
|
+
"beautifulsoup4>=4.11.1",
|
|
44
|
+
"packaging>=21.0",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
"HomePage" = "https://github.com/postgrespro/pgpro-pytest-html-json-extractor"
|
|
49
|
+
|
|
50
|
+
[project.scripts]
|
|
51
|
+
pgpro-pytest-html-json-extractor = "pgpro_pytest_html_json_extractor.__main__:cli"
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
log_file_level = "NOTSET"
|
|
56
|
+
log_file_format = "%(levelname)8s [%(asctime)s] %(message)s"
|
|
57
|
+
log_file_date_format = "%Y-%m-%d %H:%M:%S"
|
|
58
|
+
|
|
59
|
+
[tool.flake8]
|
|
60
|
+
extend-ignore = ["E501"]
|
|
61
|
+
exclude = [".git", "__pycache__", "env", "venv"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import bs4
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
import re
|
|
11
|
+
import typing
|
|
12
|
+
|
|
13
|
+
from . import __version__ as current_version
|
|
14
|
+
|
|
15
|
+
from packaging.version import Version
|
|
16
|
+
|
|
17
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
|
|
19
|
+
log = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def check_extension(
|
|
26
|
+
file_direaction: str,
|
|
27
|
+
choices: typing.List[str],
|
|
28
|
+
) -> typing.Callable:
|
|
29
|
+
assert type(file_direaction) is str
|
|
30
|
+
assert type(choices) is list
|
|
31
|
+
|
|
32
|
+
def mapper(filename):
|
|
33
|
+
ext = os.path.splitext(filename)[1].lower()
|
|
34
|
+
if ext in choices:
|
|
35
|
+
return filename
|
|
36
|
+
raise argparse.ArgumentTypeError(
|
|
37
|
+
"Bad {} file extension: '{}'. It was expecting one from {}.".format(
|
|
38
|
+
file_direaction,
|
|
39
|
+
ext,
|
|
40
|
+
choices,
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return mapper
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# ------------------------------------------------------------------------
|
|
48
|
+
def parse_arguments() -> argparse.Namespace:
|
|
49
|
+
command_parser = argparse.ArgumentParser(
|
|
50
|
+
description="A tool to extract json data from pytest-html report.",
|
|
51
|
+
epilog="Example: pgpro-pytest-html-json-extract -o report.json report.html",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
command_parser.add_argument(
|
|
55
|
+
"--version",
|
|
56
|
+
action="version",
|
|
57
|
+
version=f"%(prog)s {current_version}",
|
|
58
|
+
help="Show program's version number and exit",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
command_parser.add_argument(
|
|
62
|
+
"--out",
|
|
63
|
+
"-o",
|
|
64
|
+
help="name of the output json file",
|
|
65
|
+
type=check_extension("output", [".json"]),
|
|
66
|
+
required=True,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
command_parser.add_argument(
|
|
70
|
+
"--replace",
|
|
71
|
+
"-r",
|
|
72
|
+
help="replace output if it exists",
|
|
73
|
+
action="store_true",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Логика включения/выключения
|
|
77
|
+
command_parser.add_argument(
|
|
78
|
+
"--no-check-json",
|
|
79
|
+
dest="check_json",
|
|
80
|
+
action="store_false",
|
|
81
|
+
help="skip JSON format validation after extraction",
|
|
82
|
+
)
|
|
83
|
+
command_parser.set_defaults(check=True)
|
|
84
|
+
|
|
85
|
+
command_parser.add_argument(
|
|
86
|
+
"--verbose",
|
|
87
|
+
"-v",
|
|
88
|
+
help="level of logging verbosity",
|
|
89
|
+
default=3,
|
|
90
|
+
action="count",
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
command_parser.add_argument(
|
|
94
|
+
"input",
|
|
95
|
+
help="html file generated by pytest-html",
|
|
96
|
+
type=check_extension("input", [".html", ".htm"]),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
return command_parser.parse_args()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class PytestHtmlJsonExtractor:
|
|
103
|
+
C_MININAL_PYTEST_HTML_VERSION = "4.0.2"
|
|
104
|
+
|
|
105
|
+
# --------------------------------------------------------------------
|
|
106
|
+
@staticmethod
|
|
107
|
+
def _extract_pytest_html_version(
|
|
108
|
+
report_path,
|
|
109
|
+
report_soup: bs4.BeautifulSoup,
|
|
110
|
+
) -> str:
|
|
111
|
+
assert report_path is not None
|
|
112
|
+
assert isinstance(report_soup, bs4.BeautifulSoup)
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
Robustly extract pytest-html version from the report footer/header.
|
|
116
|
+
Example text: '... by pytest-html v4.0.2'
|
|
117
|
+
"""
|
|
118
|
+
link = report_soup.find("a", href=re.compile(r"pytest-html"))
|
|
119
|
+
if link is None:
|
|
120
|
+
raise RuntimeError(
|
|
121
|
+
"Report does not have section with pytest-html link.",
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
parent_text = link.parent.get_text()
|
|
125
|
+
|
|
126
|
+
# Looking for pattern 'v' and digits (v4.0.2)
|
|
127
|
+
match = re.search(r"v(\d+\.\d+\.\d+[\w\.]*)", parent_text)
|
|
128
|
+
if not match:
|
|
129
|
+
__class__._raise_err__cant_extract_report_version(
|
|
130
|
+
report_path,
|
|
131
|
+
parent_text,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return match.group(1)
|
|
135
|
+
|
|
136
|
+
# --------------------------------------------------------------------
|
|
137
|
+
@staticmethod
|
|
138
|
+
def exec(
|
|
139
|
+
input_path: str,
|
|
140
|
+
check_json: bool,
|
|
141
|
+
output_path: str,
|
|
142
|
+
replace: bool,
|
|
143
|
+
):
|
|
144
|
+
assert type(input_path) is str
|
|
145
|
+
assert type(check_json) is bool
|
|
146
|
+
assert type(output_path) is str
|
|
147
|
+
|
|
148
|
+
log.info("Processing report: {}".format(input_path))
|
|
149
|
+
|
|
150
|
+
with open(input_path, "r", encoding="utf-8") as f:
|
|
151
|
+
soup = bs4.BeautifulSoup(f, features="html.parser")
|
|
152
|
+
|
|
153
|
+
html_version = __class__._extract_pytest_html_version(
|
|
154
|
+
input_path,
|
|
155
|
+
soup,
|
|
156
|
+
)
|
|
157
|
+
assert type(html_version) is str
|
|
158
|
+
|
|
159
|
+
min_version = Version(__class__.C_MININAL_PYTEST_HTML_VERSION)
|
|
160
|
+
if Version(html_version) < min_version:
|
|
161
|
+
__class__._raise_err__unsupported_html_version(
|
|
162
|
+
input_path,
|
|
163
|
+
html_version,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
# load json data from the current report
|
|
167
|
+
containers = soup.select("#data-container")
|
|
168
|
+
if not containers:
|
|
169
|
+
__class__._raise_err__json_blob_is_not_found(input_path)
|
|
170
|
+
|
|
171
|
+
report_data_container = containers[0]
|
|
172
|
+
report_jsonblob = report_data_container.get("data-jsonblob")
|
|
173
|
+
|
|
174
|
+
if report_jsonblob is None:
|
|
175
|
+
__class__._raise_err__json_blob_is_not_found(
|
|
176
|
+
input_path,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
assert type(report_jsonblob) is str
|
|
180
|
+
|
|
181
|
+
if check_json:
|
|
182
|
+
log.info("Json data is checked...")
|
|
183
|
+
json.loads(report_jsonblob)
|
|
184
|
+
|
|
185
|
+
# write to file
|
|
186
|
+
write_mode = "w" if replace else "x"
|
|
187
|
+
|
|
188
|
+
with open(output_path, write_mode, encoding="utf-8") as f:
|
|
189
|
+
f.write(report_jsonblob)
|
|
190
|
+
|
|
191
|
+
return
|
|
192
|
+
|
|
193
|
+
# --------------------------------------------------------------------
|
|
194
|
+
@staticmethod
|
|
195
|
+
def _raise_err__no_section_with_version(report_path) -> typing.NoReturn:
|
|
196
|
+
err_msg = "Report [{}] does not have section with pytest-html link.".format( # noqa: E501
|
|
197
|
+
report_path
|
|
198
|
+
)
|
|
199
|
+
raise RuntimeError(err_msg)
|
|
200
|
+
|
|
201
|
+
# --------------------------------------------------------------------
|
|
202
|
+
@staticmethod
|
|
203
|
+
def _raise_err__cant_extract_report_version(
|
|
204
|
+
report_path,
|
|
205
|
+
text,
|
|
206
|
+
) -> typing.NoReturn:
|
|
207
|
+
assert report_path is not None
|
|
208
|
+
err_msg = "Cannot extract pytest-html version from {0!r}. Source file is [{1}]".format( # noqa: E501
|
|
209
|
+
text,
|
|
210
|
+
report_path,
|
|
211
|
+
)
|
|
212
|
+
raise RuntimeError(err_msg)
|
|
213
|
+
|
|
214
|
+
# --------------------------------------------------------------------
|
|
215
|
+
@staticmethod
|
|
216
|
+
def _raise_err__unsupported_html_version(
|
|
217
|
+
report_path: str,
|
|
218
|
+
version: str,
|
|
219
|
+
) -> typing.NoReturn:
|
|
220
|
+
assert report_path is not None
|
|
221
|
+
assert type(version) is str
|
|
222
|
+
err_msg = "Source file [{}] has an unsupported version [{}]. The minimal supported version is [{}].".format( # noqa: E501
|
|
223
|
+
report_path,
|
|
224
|
+
version,
|
|
225
|
+
__class__.C_MININAL_PYTEST_HTML_VERSION,
|
|
226
|
+
)
|
|
227
|
+
raise RuntimeError(err_msg)
|
|
228
|
+
|
|
229
|
+
# --------------------------------------------------------------------
|
|
230
|
+
@staticmethod
|
|
231
|
+
def _raise_err__json_blob_is_not_found(
|
|
232
|
+
report_path: str,
|
|
233
|
+
) -> typing.NoReturn:
|
|
234
|
+
assert report_path is not None
|
|
235
|
+
|
|
236
|
+
err_msg = "Source file [{}] does not countains json data.".format(
|
|
237
|
+
report_path,
|
|
238
|
+
)
|
|
239
|
+
raise RuntimeError(err_msg)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main(arguments) -> int:
|
|
246
|
+
has_errors = False
|
|
247
|
+
|
|
248
|
+
# 1. Collect from positional files
|
|
249
|
+
input_file = os.path.abspath(arguments.input)
|
|
250
|
+
if not os.path.isfile(input_file):
|
|
251
|
+
log.error(
|
|
252
|
+
"Invalid input: '{}' is not a file or does not exist.".format(
|
|
253
|
+
arguments.input,
|
|
254
|
+
),
|
|
255
|
+
)
|
|
256
|
+
has_errors = True
|
|
257
|
+
|
|
258
|
+
# 2. Check output file
|
|
259
|
+
if not arguments.replace and os.path.exists(arguments.out):
|
|
260
|
+
log.error(
|
|
261
|
+
"Invalid input: output file '{}' already exists.".format(
|
|
262
|
+
arguments.out,
|
|
263
|
+
),
|
|
264
|
+
)
|
|
265
|
+
has_errors = True
|
|
266
|
+
|
|
267
|
+
# 3. Final check
|
|
268
|
+
if has_errors:
|
|
269
|
+
log.error(
|
|
270
|
+
"Termination due to input errors.",
|
|
271
|
+
)
|
|
272
|
+
return 1
|
|
273
|
+
|
|
274
|
+
# Process each report file
|
|
275
|
+
PytestHtmlJsonExtractor.exec(
|
|
276
|
+
input_file,
|
|
277
|
+
arguments.check_json,
|
|
278
|
+
arguments.out,
|
|
279
|
+
arguments.replace,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
log.info(
|
|
283
|
+
"Successfully extracted json into {}".format(
|
|
284
|
+
arguments.out,
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
return 0
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def cli():
|
|
294
|
+
arguments = parse_arguments()
|
|
295
|
+
|
|
296
|
+
logging.basicConfig(level=int((6 - arguments.verbose) * 10))
|
|
297
|
+
|
|
298
|
+
log.debug("opts = {}".format(arguments))
|
|
299
|
+
|
|
300
|
+
r = main(arguments)
|
|
301
|
+
|
|
302
|
+
log.debug("exiting")
|
|
303
|
+
return r
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
307
|
+
|
|
308
|
+
if __name__ == "__main__":
|
|
309
|
+
sys.exit(cli())
|
|
310
|
+
|
|
311
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pgpro-pytest-html-json-extractor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A tool to extract json from pytest-html report
|
|
5
|
+
Author-email: Postgres Professional <info@postgrespro.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: HomePage, https://github.com/postgrespro/pgpro-pytest-html-json-extractor
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Classifier: Framework :: Pytest
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: beautifulsoup4>=4.11.1
|
|
26
|
+
Requires-Dist: packaging>=21.0
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
[](https://github.com/postgrespro/pgpro-pytest-html-json-extractor/actions/workflows/ci.yml)
|
|
30
|
+
[](https://badge.fury.io/py/pgpro-pytest-html-json-extractor)
|
|
31
|
+
[](https://pypi.org/project/pgpro-pytest-html-json-extractor)
|
|
32
|
+
|
|
33
|
+
# pgpro-pytest-html-json-extractor
|
|
34
|
+
A tool to extract json data from pytest-html report. Developed and maintained by Postgres Professional.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
You can install the package directly from the repository (until it's published to PyPI):
|
|
38
|
+
```bash
|
|
39
|
+
pip install pgpro-pytest-html-json-extractor
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
After installation, the tool is available via the pgpro-pytest-html-json-extractor command.
|
|
45
|
+
|
|
46
|
+
### Basic Examples
|
|
47
|
+
Extract JSON from a report:
|
|
48
|
+
```bash
|
|
49
|
+
pgpro-pytest-html-json-extractor report.html -o report.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Command Line Arguments
|
|
53
|
+
|
|
54
|
+
| Argument | Shorthand | Required | Description | Default |
|
|
55
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
56
|
+
| `--version` | | No | Show program's version number and exit | None |
|
|
57
|
+
| `--out` | `-o` | Yes | Name of the output JSON file | None |
|
|
58
|
+
| `--verbose` | `-v` | No | Level of logging verbosity | 3 |
|
|
59
|
+
| `--no-check-json` | | No | Do not validate json data after extraction | None |
|
|
60
|
+
| `--replace` | `-r` | No | Replace output if it exists | None |
|
|
61
|
+
| `input` | | Yes | Positional argument for HTML file | None |
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
1. Fork the repository.
|
|
65
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`).
|
|
66
|
+
3. Commit your changes (`git commit -m 'feat: add some amazing feature'`).
|
|
67
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
68
|
+
5. Open a Pull Request.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
72
|
+
|
|
73
|
+
© 2026 Postgres Professional
|
pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/SOURCES.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/pgpro_pytest_html_json_extractor/__init__.py
|
|
5
|
+
src/pgpro_pytest_html_json_extractor/__main__.py
|
|
6
|
+
src/pgpro_pytest_html_json_extractor.egg-info/PKG-INFO
|
|
7
|
+
src/pgpro_pytest_html_json_extractor.egg-info/SOURCES.txt
|
|
8
|
+
src/pgpro_pytest_html_json_extractor.egg-info/dependency_links.txt
|
|
9
|
+
src/pgpro_pytest_html_json_extractor.egg-info/entry_points.txt
|
|
10
|
+
src/pgpro_pytest_html_json_extractor.egg-info/requires.txt
|
|
11
|
+
src/pgpro_pytest_html_json_extractor.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
pgpro_pytest_html_json_extractor-1.0.0/src/pgpro_pytest_html_json_extractor.egg-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pgpro_pytest_html_json_extractor
|