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

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.7.9.tar.gz (73.2 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.7.9-py2.py3-none-any.whl (88.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file reportportal_client-5.7.9.tar.gz.

File metadata

  • Download URL: reportportal_client-5.7.9.tar.gz
  • Upload date:
  • Size: 73.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for reportportal_client-5.7.9.tar.gz
Algorithm Hash digest
SHA256 fc823a01c6a90cd62717408a314c574a5d1162400b5ee82c0c58931bc3a859f0
MD5 ac0cb7a6c82eba3726d0434819197f4f
BLAKE2b-256 0db99cb575d887634d1807bf83d7166e3efeb1a3a7c865ed27a51bac9dd9a2ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for reportportal_client-5.7.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2f127ea9e83d3c90af06de634e9e6af0068ae9bc93104850cb956e075a6b848d
MD5 71626ff8f7c0c22e1f13fd06e472c0fa
BLAKE2b-256 220e2b8da47a7a5ca8333b8c25966c72540c43ecdc41e1939907ff95f1781e17

See more details on using hashes here.

Release history Release notifications | RSS feed

5.7.10

2 files

This release

5.7.9 This release

2 files

5.7.8

2 files

5.7.7

2 files

5.7.6

2 files

5.7.5

2 files

5.7.4

2 files

5.7.3

2 files

5.7.2

2 files

5.7.1

2 files

5.7.0

2 files

5.6.7

2 files

5.6.6

2 files

5.6.5

2 files

5.6.4

2 files

5.6.3

2 files

5.6.2

2 files

5.6.1

2 files

5.6.0

2 files

5.5.10

2 files

5.5.9

2 files

5.5.8

2 files

5.5.7

2 files

5.5.6

2 files

5.5.5

2 files

5.5.4

2 files

5.5.3

2 files

5.5.2

2 files

5.5.1

2 files

5.5.0

2 files

5.4.1

2 files

5.4.0

2 files

5.3.5

2 files

5.3.4

2 files

5.3.3

2 files

5.3.2

2 files

5.3.1

2 files

5.3.0

2 files

5.2.5

2 files

5.2.4

2 files

5.2.3

2 files

5.2.2

2 files

5.2.1

2 files

5.2.0

2 files

5.1.0

2 files

5.0.12

2 files

5.0.11

2 files

5.0.10

2 files

5.0.9

2 files

5.0.8

2 files

5.0.7

2 files

5.0.6

2 files

5.0.5

2 files

5.0.3

2 files

5.0.2

2 files

5.0.1

2 files

5.0.0

2 files

4.0.0

2 files

3.2.3

2 files

3.2.0

2 files

3.1.0

2 files

3.0.0

2 files

2.6.0

2 files

2.5.4

1 file

2.5.3

1 file

2.5.2

1 file

2.5.1

1 file

2.5.0

1 file

Supported by

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