Skip to content

Commit 3633f82

Browse files
committed
add logging to readme example
1 parent 0554069 commit 3633f82

File tree

1 file changed

+81
-20
lines changed

1 file changed

+81
-20
lines changed

README.md

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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)
@@ -13,7 +13,9 @@ Library used only for implementors of custom listeners for ReportPortal
1313

1414
The latest stable version is available on PyPI:
1515

16-
pip install reportportal-client
16+
```
17+
pip install reportportal-client
18+
```
1719

1820

1921
## Usage
@@ -30,36 +32,95 @@ Main classes are:
3032
Basic usage example:
3133

3234
```python
35+
import os
36+
import subprocess
3337
from time import time
34-
from reportportal_client import (ReportPortalService,
38+
from mimetypes import guess_type
39+
40+
from reportportal_client import (ReportPortalService,
3541
FinishExecutionRQ,
3642
StartLaunchRQ, StartTestItemRQ,
3743
FinishTestItemRQ, SaveLogRQ)
3844

45+
3946
def timestamp():
4047
return str(int(time() * 1000))
4148

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

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

52-
#Start Launch
59+
# Create start launch request.
5360
sl_rq = StartLaunchRQ(name=launch_name,
5461
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)
63124
```
64125

65126
# Copyright Notice

0 commit comments

Comments
 (0)