Skip to main content

Python client for Report Portal v5.

Project description

ReportPortal python client

PyPI Python versions Build Status codecov.io Join Slack chat! stackoverflow Build with Love

Library used only for implementors of custom listeners for ReportPortal

Already implemented listeners:

Installation

The latest stable version is available on PyPI:

pip install reportportal-client

Usage

Basic usage example:

import os
import subprocess
from mimetypes import guess_type

from reportportal_client import RPClient
from reportportal_client.helpers import timestamp

endpoint = "http://docker.local:8080"
project = "default"
# You can get UUID from user profile page in the Report Portal.
token = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
launch_name = "Test launch"
launch_doc = "Testing logging with attachment."


client = RPClient(endpoint=endpoint, project=project,
                  token=token)

# Start log upload thread
client.start()

# Start launch.
launch = client.start_launch(name=launch_name,
                             start_time=timestamp(),
                             description=launch_doc)

item_id = client.start_test_item(name="Test Case",
                                 description="First Test Case",
                                 start_time=timestamp(),
                                 attributes=[{"key": "key", "value": "value"},
                                             {"value", "tag"}],
                                 item_type="STEP",
                                 parameters={"key1": "val1",
                                             "key2": "val2"})

# Create text log message with INFO level.
client.log(time=timestamp(),
           message="Hello World!",
           level="INFO")

# Create log message with attached text output and WARN level.
client.log(time=timestamp(),
           message="Too high memory usage!",
           level="WARN",
           attachment={
               "name": "free_memory.txt",
               "data": subprocess.check_output("free -h".split()),
               "mime": "text/plain"
           })

# Create log message with binary file, INFO level and custom mimetype.
image = "/tmp/image.png"
with open(image, "rb") as fh:
    attachment = {
        "name": os.path.basename(image),
        "data": fh.read(),
        "mime": guess_type(image)[0] or "application/octet-stream"
    }
    client.log(timestamp(), "Screen shot of issue.", "INFO", attachment)

client.finish_test_item(item_id=item_id, end_time=timestamp(), status="PASSED")

# Finish launch.
client.finish_launch(end_time=timestamp())

# Due to async nature of the service we need to call terminate() method which
# ensures all pending requests to server are processed.
# Failure to call terminate() may result in lost data.
client.terminate()

Send attachment (screenshots)

The client uses requests library for working with RP and the same semantics to work with attachments (data).

To log an attachment you need to pass file content and metadata to ``

import logging

from reportportal_client import RPLogger, RPLogHandler

logging.setLoggerClass(RPLogger)
rp_logger = logging.getLogger(__name__)
rp_logger.setLevel(logging.DEBUG)
rp_logger.addHandler(RPLogHandler())

screenshot_file_path = 'path/to/file.png'

with open(screenshot_file_path, "rb") as image_file:
    file_data = image_file.read()

    # noinspection PyArgumentList
    rp_logger.info(
        "Some Text Here",
        attachment={"name": "test_name_screenshot.png",
                    "data": file_data,
                    "mime": "image/png"}
    )

Copyright Notice

Licensed under the Apache 2.0 license (see the LICENSE.txt file).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reportportal-client-5.3.3.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reportportal_client-5.3.3-py2.py3-none-any.whl (58.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file reportportal-client-5.3.3.tar.gz.

File metadata

  • Download URL: reportportal-client-5.3.3.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for reportportal-client-5.3.3.tar.gz
Algorithm Hash digest
SHA256 b0d6b1b0d69b34354463c9b6116c0afc34dcde787ba8555f4ab9f411f3d77f89
MD5 8901c30f1f9c5ab6cee2aeb4f801a3cb
BLAKE2b-256 764ce00c2f1636a23bdc02c557c46a8b930ed41fe87c98acbff6b66b1f75f038

See more details on using hashes here.

File details

Details for the file reportportal_client-5.3.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for reportportal_client-5.3.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ee9c4b4e9f53639c50d955d199cb020519da7fe04cc5b5daaea574623dd34ca9
MD5 ccdf88817876296f5e590d670c95e239
BLAKE2b-256 048aaf411901a6a22091b7d1e49a56f13e19118cf36b7af0892e234b8676f79a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page