Skip to content

Commit f4171a8

Browse files
author
Alexander.Iljushkin
authored
Merge pull request #8 from krasoffski/readme
Add more complex example usage to readme file.
2 parents 21bffd0 + 64c2b53 commit f4171a8

File tree

1 file changed

+87
-21
lines changed

1 file changed

+87
-21
lines changed

README.md

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
# ReportPortal python client
1+
# ReportPortal python client
22

33
[![PyPI](https://img.shields.io/pypi/v/reportportal-client.svg?maxAge=2592000)](https://pypi.python.org/pypi/reportportal-client)
44
[![Build Status](https://travis-ci.org/reportportal/client-Python.svg?branch=master)](https://travis-ci.org/reportportal/client-Python)
55

66
Library used only for implementors of custom listeners for ReportPortal
77

8+
89
## 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)
1013

1114

1215
## Installation
1316

1417
The latest stable version is available on PyPI:
1518

16-
pip install reportportal-client
19+
```
20+
pip install reportportal-client
21+
```
1722

1823

1924
## Usage
@@ -30,38 +35,99 @@ Main classes are:
3035
Basic usage example:
3136

3237
```python
38+
import os
39+
import subprocess
3340
from time import time
34-
from reportportal_client import (ReportPortalService,
41+
from mimetypes import guess_type
42+
43+
from reportportal_client import (ReportPortalService,
3544
FinishExecutionRQ,
3645
StartLaunchRQ, StartTestItemRQ,
3746
FinishTestItemRQ, SaveLogRQ)
3847

48+
3949
def timestamp():
4050
return str(int(time() * 1000))
4151

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"
4752

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)
5161

52-
#Start Launch
62+
# Create start launch request.
5363
sl_rq = StartLaunchRQ(name=launch_name,
5464
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)
63127
```
64128

129+
65130
# Copyright Notice
131+
66132
Licensed under the [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html)
67133
license (see the LICENSE.txt file).

0 commit comments

Comments
 (0)