Skip to main content

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 ReportPortal.
api_key = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
launch_name = "Test launch"
launch_doc = "Testing logging with attachment."


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

# 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).

Metadata

Release files for reportportal-client 5.7.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reportportal-client 5.7.11
File Size Uploaded Provenance Actions
reportportal_client-5.7.11.tar.gz 73.2 kB Without provenance Details for reportportal_client-5.7.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for reportportal-client 5.7.11
File Interpreter ABI Platform Actions
reportportal_client-5.7.11-py2.py3-none-any.whl Python 2, Python 3 none any Details for reportportal_client-5.7.11-py2.py3-none-any.whl

Total release size: 161.9 kB

Release files / reportportal_client-5.7.11.tar.gz

Download URL reportportal_client-5.7.11.tar.gz
Size 73.2 kB
Tags Source
SHA-256 checksum
How to use checksums
26b62e7c2a9d377745d5a3bcb5bc9a44b914bf23e06c405582436129533f076f
BLAKE2b-256 checksum
How to use checksums
47a6494e50c44890434b22753fe4025342f9f4a38edd0e7258010d61fc288f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / reportportal_client-5.7.11-py2.py3-none-any.whl

Download URL reportportal_client-5.7.11-py2.py3-none-any.whl
Size 88.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e124f32f6e3939b8284bf7014d4fd49924deee8c031691338566e7c9c6ce7506
BLAKE2b-256 checksum
How to use checksums
0ed81455a9fe287f6549af24ff9a29a9d71d23918a5bd25d2b778ad28084782d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for reportportal-client 5.7.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

5.7.11 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page