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