1
- # ReportPortal python client
1
+ # ReportPortal python client
2
2
3
3
[ ![ PyPI] ( https://img.shields.io/pypi/v/reportportal-client.svg?maxAge=2592000 )] ( https://pypi.python.org/pypi/reportportal-client )
4
4
[ ![ Build Status] ( https://travis-ci.org/reportportal/client-Python.svg?branch=master )] ( https://travis-ci.org/reportportal/client-Python )
@@ -13,7 +13,9 @@ Library used only for implementors of custom listeners for ReportPortal
13
13
14
14
The latest stable version is available on PyPI:
15
15
16
- pip install reportportal-client
16
+ ```
17
+ pip install reportportal-client
18
+ ```
17
19
18
20
19
21
## Usage
@@ -30,36 +32,95 @@ Main classes are:
30
32
Basic usage example:
31
33
32
34
``` python
35
+ import os
36
+ import subprocess
33
37
from time import time
34
- from reportportal_client import (ReportPortalService,
38
+ from mimetypes import guess_type
39
+
40
+ from reportportal_client import (ReportPortalService,
35
41
FinishExecutionRQ,
36
42
StartLaunchRQ, StartTestItemRQ,
37
43
FinishTestItemRQ, SaveLogRQ)
38
44
45
+
39
46
def timestamp ():
40
47
return str (int (time() * 1000 ))
41
48
42
- endpoint = " https://urlpreportportal"
43
- project = " ProjectName"
44
- token = " uuid" # you can get it from profile page in ReportPortal
45
- launch_name = " name for launch"
46
- launch_doc = " Some text documentation for launch"
47
49
48
- service = ReportPortalService(endpoint = endpoint,
49
- project = project,
50
- token = token)
50
+ endpoint = " http://10.6.40.6:8080"
51
+ project = " default"
52
+ # You can get UUID from user profile page in the Report Portal.
53
+ token = " 1adf271d-505f-44a8-ad71-0afbdf8c83bd"
54
+ launch_name = " Test launch"
55
+ launch_doc = " Testing logging with attachment."
56
+
57
+ service = ReportPortalService(endpoint = endpoint, project = project, token = token)
51
58
52
- # Start Launch
59
+ # Create start launch request.
53
60
sl_rq = StartLaunchRQ(name = launch_name,
54
61
start_time = timestamp(),
55
- description = launch_doc)
56
- r = service.start_launch(sl_rq)
57
- launch_id = r.id
58
-
59
- # Finish Launch
60
- fl_rq = FinishExecutionRQ(end_time = timestamp(),
61
- status = " PASSED" )
62
- service.finish_launch(launch_id, fl_rq)
62
+ description = launch_doc)
63
+
64
+ # Start launch.
65
+ launch = service.start_launch(sl_rq)
66
+
67
+ # Create start test item request.
68
+ sti_rq = StartTestItemRQ(name = " Test Case" ,
69
+ description = " First Test Case" ,
70
+ tags = [" Image" , " Smoke" ],
71
+ start_time = timestamp(),
72
+ launch_id = launch.id,
73
+ type = " TEST" )
74
+
75
+ # Start test item.
76
+ test = service.start_test_item(parent_item_id = None , start_test_item_rq = sti_rq)
77
+
78
+ # Create text log message with INFO level.
79
+ service.log(SaveLogRQ(item_id = test.id,
80
+ time = timestamp(),
81
+ message = " Hello World!" ,
82
+ level = " INFO" ))
83
+
84
+ # Create log message with attached text output and WARN level.
85
+ service.attach(SaveLogRQ(item_id = test.id,
86
+ time = timestamp(),
87
+ message = " Too high memory usage!" ,
88
+ level = " WARN" ),
89
+ name = " free_memory.txt" ,
90
+ data = subprocess.check_output(" free -h" .split()))
91
+
92
+ # Create log message with piped binary file, INFO level and custom mimetype.
93
+ image = " /tmp/image.png"
94
+ sl_rq = SaveLogRQ(test.id, timestamp(), " Screen shot of issue." , " INFO" )
95
+ with open (image, " rb" ) as fh:
96
+ service.attach(save_log_rq = sl_rq,
97
+ name = os.path.basename(image),
98
+ data = fh,
99
+ mime = guess_type(image)[0 ] or " application/octet-stream" )
100
+
101
+ # Create log message with binary data and INFO level.
102
+ filebin = " /tmp/file.bin"
103
+ with open (filebin, " rb" ) as fd:
104
+ bindata = fd.read()
105
+ # Note here that we pass binary data instead of file handle.
106
+ service.attach(SaveLogRQ(item_id = test.id,
107
+ time = timestamp(),
108
+ message = " Binary data file." ,
109
+ level = " INFO" ),
110
+ name = " file.bin" ,
111
+ data = bindata,
112
+ mime = " application/octet-stream" )
113
+
114
+ # Create finish test item request.
115
+ fti_rq = FinishTestItemRQ(end_time = timestamp(), status = " PASSED" )
116
+
117
+ # Finish test item.
118
+ service.finish_test_item(item_id = test.id, finish_test_item_rq = fti_rq)
119
+
120
+ # Create finish launch request.
121
+ fl_rq = FinishExecutionRQ(end_time = timestamp(), status = " PASSED" )
122
+ # Finish launch.
123
+ service.finish_launch(launch.id, fl_rq)
63
124
```
64
125
65
126
# Copyright Notice
0 commit comments