pytest-test-radar 0.0.1a1__py3-none-any.whl

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
+ # The MIT License (MIT).
2
+ #
3
+ # Copyright (c) 2024 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>
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,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ # OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # The MIT License (MIT).
2
+ #
3
+ # Copyright (c) 2024 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>
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,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ # OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ import base64
24
+ import datetime
25
+ import zlib
26
+
27
+ import httpx
28
+ import pytest
29
+
30
+ http_session = httpx.Client()
31
+ session_start_date = datetime.datetime.now(tz=datetime.UTC).isoformat()
32
+
33
+
34
+ def pytest_addoption(parser: pytest.Parser) -> None:
35
+ help_text = 'Test radar endpoint'
36
+ parser.addini('radar_endpoint', type='string', help=help_text)
37
+ parser.addoption('--radar-endpoint', help=help_text)
38
+
39
+
40
+ def pytest_configure(config: pytest.Config) -> None:
41
+ if config.option.help:
42
+ return
43
+ if not config.getini('radar_endpoint') and not config.getoption('--radar-endpoint'):
44
+ msg = 'Provide `--radar-endpoint` in cli option or `radar_endpoint` in config file`'
45
+ raise pytest.UsageError(msg)
46
+
47
+
48
+ def pytest_sessionstart(session: pytest.Session) -> None:
49
+ http_session.base_url = session.config.getoption('--radar-endpoint') or session.config.getini('radar_endpoint')
50
+
51
+
52
+ def pytest_runtest_logreport(report: pytest.TestReport) -> None:
53
+ logs = ''
54
+ if report.when == 'call' and report.failed:
55
+ compressed = zlib.compress(report.longreprtext.encode('utf-8'))
56
+ encoded = base64.b64encode(compressed)
57
+ logs = encoded.decode('utf-8')
58
+ if report.when == 'call':
59
+ try:
60
+ response = http_session.post(
61
+ '/api/v1/test_record/create/',
62
+ json={
63
+ 'label': report.nodeid,
64
+ 'timestamp': session_start_date,
65
+ 'logs': logs,
66
+ 'success': not report.failed,
67
+ },
68
+ )
69
+ response.raise_for_status()
70
+ except httpx.HTTPError as exc:
71
+ print(f'Some error occured on sending test record to radar. Exc: {exc}')
72
+
73
+
74
+ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
75
+ http_session.close()
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-test-radar
3
+ Version: 0.0.1a1
4
+ Summary: A pytest plugin to send test statistics to Test Radar.
5
+ Project-URL: Homepage, https://github.com/yourusername/pytest-test-radar
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Keywords: flaky,plugin,pytest,test
9
+ Classifier: Framework :: Pytest
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: httpx>=0.28.1
15
+ Description-Content-Type: text/markdown
16
+
17
+ <!--
18
+ The MIT License (MIT).
19
+
20
+ Copyright (c) 2024 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all
30
+ copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
35
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
36
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
37
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
38
+ OR OTHER DEALINGS IN THE SOFTWARE.
39
+ -->
40
+
41
+ # pytest-test-radar
42
+
43
+ pytest-test-radar is a pytest plugin designed to send test execution statistics
44
+ to a centralized server. This allows teams to monitor flaky tests,
45
+ track performance, and identify redundant or overly stable tests that might
46
+ not be adding value to the test suite.
47
+
48
+ ## Features
49
+
50
+ - Collects test execution statistics, including:
51
+ - Test name
52
+ - Outcome (passed, failed, skipped)
53
+ - Execution duration
54
+ - Sends data to a configured HTTP endpoint.
55
+ - Easy integration with any centralized monitoring system.
56
+
57
+ ## Installation
58
+
59
+ You can install it to your project dependencies:
60
+
61
+ ```bash
62
+ pip install pytest-test-radar
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ Run pytest with the --test-radar-endpoint option to specify the server where statistics will be sent:
68
+
69
+ ```bash
70
+ pytest --test-radar-endpoint="http://your-server.com/api/test-results"
71
+ ```
72
+
73
+ ## Example
74
+
75
+ Create a sample test file:
76
+
77
+ ```python
78
+ # test_sample.py
79
+ def test_pass():
80
+ assert 1 == 1
81
+
82
+ def test_fail():
83
+ assert 1 == 2
84
+ ```
85
+
86
+ Run the tests with the plugin:
87
+
88
+ ```bash
89
+ pytest test_sample.py --test-radar-endpoint="http://localhost:8000/api/test-results"
90
+ ```
91
+
92
+ This will send the following payload to the specified endpoint:
93
+
94
+ ```json
95
+ {
96
+ "total_tests": 2,
97
+ "results": [
98
+ {
99
+ "test_name": "test_sample.py::test_pass",
100
+ "outcome": "passed",
101
+ "duration": 0.001
102
+ },
103
+ {
104
+ "test_name": "test_sample.py::test_fail",
105
+ "outcome": "failed",
106
+ "duration": 0.002
107
+ }
108
+ ]
109
+ }
110
+ ```
@@ -0,0 +1,7 @@
1
+ pytest_test_radar/__init__.py,sha256=mOJVtg77FU7cAoy7ir2HJi-j9iZGIoFLkNq09Mio6EM,1149
2
+ pytest_test_radar/plugin.py,sha256=1NnFAvcZxAefiMf5GWnl-MCIqfdfkYbtZoXuniu8VuM,2955
3
+ pytest_test_radar-0.0.1a1.dist-info/METADATA,sha256=cXIitz4IV7rXJxiExoZ63mL_fVdVtBSTpq6Zx5541vQ,3110
4
+ pytest_test_radar-0.0.1a1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
5
+ pytest_test_radar-0.0.1a1.dist-info/entry_points.txt,sha256=9F-A6rwGFGdDz_P--tAO29NlKMmdhkuLUqaGRUprfjQ,49
6
+ pytest_test_radar-0.0.1a1.dist-info/licenses/LICENSE,sha256=Gc1FKRVA4g5qs0MnMY6K-zVZr-SQey28xj98ARzxr6E,1111
7
+ pytest_test_radar-0.0.1a1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ test_radar = pytest_test_radar.plugin
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT).
2
+
3
+ Copyright (c) 2024 Almaz Ilaletdinov <a.ilaletdinov@yandex.ru>
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,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ OR OTHER DEALINGS IN THE SOFTWARE.