flakytest 2023.0b0__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.
- flakytest/__about__.py +4 -0
- flakytest/__init__.py +3 -0
- flakytest/hook.py +109 -0
- flakytest-2023.0b0.dist-info/METADATA +65 -0
- flakytest-2023.0b0.dist-info/RECORD +8 -0
- flakytest-2023.0b0.dist-info/WHEEL +4 -0
- flakytest-2023.0b0.dist-info/entry_points.txt +2 -0
- flakytest-2023.0b0.dist-info/licenses/LICENSE.txt +9 -0
flakytest/__about__.py
ADDED
flakytest/__init__.py
ADDED
flakytest/hook.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2023-present Anže Pečar <anze@pecar.me>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# root
|
|
6
|
+
# └── pytest_cmdline_main
|
|
7
|
+
# ├── pytest_plugin_registered
|
|
8
|
+
# ├── pytest_configure
|
|
9
|
+
# │ └── pytest_plugin_registered
|
|
10
|
+
# ├── pytest_sessionstart
|
|
11
|
+
# │ ├── pytest_plugin_registered
|
|
12
|
+
# │ └── pytest_report_header
|
|
13
|
+
# ├── pytest_collection
|
|
14
|
+
# │ ├── pytest_collectstart
|
|
15
|
+
# │ ├── pytest_make_collect_report
|
|
16
|
+
# │ │ ├── pytest_collect_file
|
|
17
|
+
# │ │ │ └── pytest_pycollect_makemodule
|
|
18
|
+
# │ │ └── pytest_pycollect_makeitem
|
|
19
|
+
# │ │ └── pytest_generate_tests
|
|
20
|
+
# │ │ └── pytest_make_parametrize_id
|
|
21
|
+
# │ ├── pytest_collectreport
|
|
22
|
+
# │ ├── pytest_itemcollected
|
|
23
|
+
# │ ├── pytest_collection_modifyitems
|
|
24
|
+
# │ └── pytest_collection_finish
|
|
25
|
+
# │ └── pytest_report_collectionfinish
|
|
26
|
+
# ├── pytest_runtestloop
|
|
27
|
+
# │ └── pytest_runtest_protocol
|
|
28
|
+
# │ ├── pytest_runtest_logstart
|
|
29
|
+
# │ ├── pytest_runtest_setup
|
|
30
|
+
# │ │ └── pytest_fixture_setup
|
|
31
|
+
# │ ├── pytest_runtest_makereport
|
|
32
|
+
# │ ├── pytest_runtest_logreport
|
|
33
|
+
# │ │ └── pytest_report_teststatus
|
|
34
|
+
# │ ├── pytest_runtest_call
|
|
35
|
+
# │ │ └── pytest_pyfunc_call
|
|
36
|
+
# │ ├── pytest_runtest_teardown
|
|
37
|
+
# │ │ └── pytest_fixture_post_finalizer
|
|
38
|
+
# │ └── pytest_runtest_logfinish
|
|
39
|
+
# ├── pytest_sessionfinish
|
|
40
|
+
# │ └── pytest_terminal_summary
|
|
41
|
+
# └── pytest_unconfigure
|
|
42
|
+
|
|
43
|
+
# def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
|
44
|
+
# # Add a section?
|
|
45
|
+
# ...
|
|
46
|
+
import http.client
|
|
47
|
+
import json
|
|
48
|
+
import os
|
|
49
|
+
import traceback
|
|
50
|
+
|
|
51
|
+
token = os.environ.get("FLAKYTEST_SECRET_TOKEN")
|
|
52
|
+
host = os.environ.get("FLAKYTEST_HOST", "flakytest.dev")
|
|
53
|
+
|
|
54
|
+
muted_tests = []
|
|
55
|
+
tests = []
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def pytest_collection_modifyitems(items):
|
|
59
|
+
if not token:
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
headers = {"Content-type": "application/json", "Accept": "text/plain", "Authorization": token}
|
|
63
|
+
conn = http.client.HTTPConnection("localhost", 8001)
|
|
64
|
+
conn.request("GET", "/muted_tests/", headers=headers)
|
|
65
|
+
muted_tests[:] = json.loads(conn.getresponse().read().decode())["result"]
|
|
66
|
+
muted_test_set = {test["name"] for test in muted_tests}
|
|
67
|
+
items[:] = [item for item in items if item.nodeid not in muted_test_set]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def pytest_collection_finish(session):
|
|
71
|
+
if not token:
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
headers = {"Content-type": "application/json", "Accept": "text/plain", "Authorization": token}
|
|
75
|
+
conn = http.client.HTTPConnection(host)
|
|
76
|
+
conn.request("POST", "/sessions/", headers=headers)
|
|
77
|
+
session.stash["session_id"] = conn.getresponse().read().decode()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def pytest_sessionfinish(session, exitstatus):
|
|
81
|
+
# Send report end here?
|
|
82
|
+
if not token:
|
|
83
|
+
return
|
|
84
|
+
json_data = json.dumps(
|
|
85
|
+
{"tests": tests + muted_tests, "exit_status": exitstatus.name if exitstatus != 0 else "OK"}
|
|
86
|
+
).encode()
|
|
87
|
+
headers = {"Content-type": "application/json", "Accept": "text/plain", "Authorization": token}
|
|
88
|
+
conn = http.client.HTTPConnection(host)
|
|
89
|
+
conn.request("POST", f"/sessions/{session.stash['session_id']}/finish", json_data, headers)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def pytest_runtest_makereport(item, call):
|
|
93
|
+
if call.when == "call":
|
|
94
|
+
# Get the test status
|
|
95
|
+
if call.excinfo is None:
|
|
96
|
+
status = "PASS"
|
|
97
|
+
elif call.excinfo.type == AssertionError:
|
|
98
|
+
status = "FAIL"
|
|
99
|
+
else:
|
|
100
|
+
status = "ERROR"
|
|
101
|
+
|
|
102
|
+
tests.append(
|
|
103
|
+
{
|
|
104
|
+
"name": item.nodeid,
|
|
105
|
+
"status": status,
|
|
106
|
+
"duration": call.duration,
|
|
107
|
+
"output": "\n".join(traceback.format_tb(call.excinfo.tb)) if call.excinfo else "",
|
|
108
|
+
}
|
|
109
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flakytest
|
|
3
|
+
Version: 2023.0b0
|
|
4
|
+
Summary: Pytest plugin for flakytest.dev
|
|
5
|
+
Project-URL: Documentation, https://github.com/anze3db/flakytest-python#readme
|
|
6
|
+
Project-URL: Changelog, https://github.com/anze3db/flakytest-python/blob/main/CHANGELOG.md
|
|
7
|
+
Project-URL: Issues, https://github.com/anze3db/flakytest-python/issues
|
|
8
|
+
Project-URL: Source, https://github.com/anze3db/flakytest-python
|
|
9
|
+
Project-URL: Mastodon, https://fosstodon.org/@anze3db
|
|
10
|
+
Project-URL: Twitter, https://twitter.com/anze3db
|
|
11
|
+
Author-email: Anže Pečar <anze@pecar.me>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE.txt
|
|
14
|
+
Keywords: flaky,pytest,test
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Framework :: Pytest
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# flakytest-python
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/flakytest)
|
|
33
|
+
[](https://pypi.org/project/flakytest)
|
|
34
|
+
|
|
35
|
+
-----
|
|
36
|
+
|
|
37
|
+
**Table of Contents**
|
|
38
|
+
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [License](#license)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
> [!WARNING]
|
|
45
|
+
> flakytest is currently in beta. It is not recommended to use it in production.
|
|
46
|
+
|
|
47
|
+
```console
|
|
48
|
+
pip install flakytest --pre
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Obtain the `FLAKYTEST_SECRET_TOKEN` from [flakytest.dev](https://flakytest.dev/) and set it as an environment variable (e.g. your secrets store in your CI/CD pipeline)
|
|
52
|
+
|
|
53
|
+
```console
|
|
54
|
+
export FLAKYTEST_SECRET_TOKEN=****************************
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Run your tests with `pytest` normally
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
pytest
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
`flakytest` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
flakytest/__about__.py,sha256=z4fdrbOVROjSFViwHN3We6n6o1T7r7rrmV8QbbRD00Q,126
|
|
2
|
+
flakytest/__init__.py,sha256=b6taqPEJ1KJxDwpKbtiSXfuZLNMoLxsDpDlzrDm9060,101
|
|
3
|
+
flakytest/hook.py,sha256=Ejc2DRPNoKAJRcCO0YPTjlI3faT8kmamM0hrlYcYmds,3762
|
|
4
|
+
flakytest-2023.0b0.dist-info/METADATA,sha256=bT7D2s4WnCs-TInAZXj3lNV0qEH5y1wnLIR7S0jlbK8,2188
|
|
5
|
+
flakytest-2023.0b0.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
|
|
6
|
+
flakytest-2023.0b0.dist-info/entry_points.txt,sha256=H7AHXIa8AhIw0JParmB-GSUb2axPZRY7VhbO_bmOBkk,38
|
|
7
|
+
flakytest-2023.0b0.dist-info/licenses/LICENSE.txt,sha256=W_TqC0HJzB0rn6QOIDZmpxpCmFFSHgDjVCoEWXPX300,1093
|
|
8
|
+
flakytest-2023.0b0.dist-info/RECORD,,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Anže Pečar <anze@pecar.me>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|