-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_file_to_txt.py
62 lines (51 loc) · 1.79 KB
/
report_file_to_txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Reads in a test_report.json which has been created by pytest and
creates a csv file of the results with relevant info.
"""
import argparse
import json
from pymongo import MongoClient
import csv
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Add all the tests within test_report.json to the remote MongoDB."
)
parser.add_argument(
"--workflow-link",
type=str,
help="Link to the GitHub actions workflow corresponding to this test.",
)
args = parser.parse_args()
json_report_file = "test_report.json"
# load in the test report
with open(json_report_file, "r") as file:
data = json.load(file)
tests_data = data.get("tests", None)
all_documents = []
# create a .txt file
for test in tests_data:
test_path, test_function_args = test["nodeid"].split("::")
split_path = test_path.split("/", 1)
integration = split_path[0]
test_file = split_path[1]
_, test_args = test_function_args.split("[")
test_args = test_args.replace("]", "")
test_args = test_args.split("-")
target, mode, backend_compile = test_args
integration_fn = test["call"]["stdout"].split("\n")[0]
document = {
"target": target,
"mode": mode,
"backend_compile": backend_compile,
"function": integration_fn,
"workflow_link": args.workflow_link,
"outcome": test["outcome"],
}
all_documents.append(document)
# write to a txt file
with open("test_results.txt", "w") as file:
for document in all_documents:
line = ""
for v in document.values():
line += v + ","
file.write(line + "\n")