Skip to main content

Agent for Reporting results of tests to the Report Portal

Project description

ReportPortal integration for pytest framework

Pytest plugin for reporting test results of the Pytest to the ReportPortal.

DISCLAIMER: We use Google Analytics for sending anonymous usage information such as agent's and client's names, and their versions after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the ReportPortal team only and is not supposed for sharing with 3rd parties.

PyPI Python versions Tests codecov Join Slack chat! stackoverflow Build with Love

Installation

To install pytest plugin execute next command in a terminal:

pip install pytest-reportportal

Look through the CONTRIBUTING.rst for contribution guidelines.

Configuration

Prepare the config file pytest.ini in root directory of tests or specify any one using pytest command line option:

py.test -c config.cfg

The pytest.ini file should have next mandatory fields:

  • rp_project - name of project in ReportPortal
  • rp_endpoint - address of ReportPortal Server

And one type of authorization: API Key or OAuth 2.0 Password grant. You can do this by setting:

  • rp_api_key or RP_API_KEY environment variable. You can get it in the User Profile section on the UI.

Or:

  • rp_oauth_uri - OAuth 2.0 token endpoint URL for password grant authentication. Required if API key is not used.
  • rp_oauth_username - OAuth 2.0 username for password grant authentication. Required if OAuth 2.0 is used.
  • rp_oauth_password - OAuth 2.0 password for password grant authentication. Required if OAuth 2.0 is used.
  • rp_oauth_client_id - OAuth 2.0 client identifier. Required if OAuth 2.0 is used.
  • rp_oauth_client_secret - OAuth 2.0 client secret. Optional for OAuth 2.0 authentication.
  • rp_oauth_scope - OAuth 2.0 access token scope. Optional for OAuth 2.0 authentication.

Example of pytest.ini:

[pytest]
rp_api_key = fb586627-32be-47dd-93c1-678873458a5f
rp_endpoint = http://192.168.1.10:8080
rp_project = user_personal
rp_launch = AnyLaunchName
rp_launch_attributes = 'PyTest' 'Smoke'
rp_launch_description = 'Smoke test'
rp_ignore_attributes = 'xfail' 'usefixture'

There are also optional parameters: https://reportportal.io/docs/log-data-in-reportportal/test-framework-integration/Python/pytest/

Examples

For logging of the test item flow to ReportPortal, please, use the python logging handler provided by plugin like below:

in conftest.py:

import logging

import pytest

from reportportal_client import RPLogger


@pytest.fixture(scope="session")
def rp_logger():
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    logging.setLoggerClass(RPLogger)
    return logger

in tests:

# In this case only INFO messages will be sent to the ReportPortal.
def test_one(rp_logger):
    rp_logger.info("Case1. Step1")
    x = "this"
    rp_logger.info("x is: %s", x)
    assert 'h' in x

    # Message with an attachment.
    import subprocess
    free_memory = subprocess.check_output("free -h".split())
    rp_logger.info(
        "Case1. Memory consumption",
        attachment={
            "name": "free_memory.txt",
            "data": free_memory,
            "mime": "application/octet-stream",
        },
    )

    # This debug message will not be sent to the ReportPortal.
    rp_logger.debug("Case1. Debug message")

Launching

To run test with ReportPortal you must provide --reportportal flag:

py.test ./tests --reportportal

Check the documentation to find more detailed information about how to integrate pytest with ReportPortal using the agent: https://reportportal.io/docs/log-data-in-reportportal/test-framework-integration/Python/pytest/

Copyright Notice

Licensed under the Apache 2.0 license (see the LICENSE 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

pytest_reportportal-5.6.0.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

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

pytest_reportportal-5.6.0-py2.py3-none-any.whl (32.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest_reportportal-5.6.0.tar.gz.

File metadata

  • Download URL: pytest_reportportal-5.6.0.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_reportportal-5.6.0.tar.gz
Algorithm Hash digest
SHA256 da378f95f4ca8a0bf7e771b265b45f72e5cb05f72b8f53dbe4b80ad73d90d62f
MD5 c7644241f6a27df3e1f518d9d33729b7
BLAKE2b-256 b8bff181489815b636ec927229761b9efe8584a1c9c402fe64da025d91bbc6d4

See more details on using hashes here.

File details

Details for the file pytest_reportportal-5.6.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_reportportal-5.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c8df63a09115c77faba2500799b9076dc477e49584caece1ba0df18067c14c12
MD5 507bddf139270a8630da6bf1defc2e4f
BLAKE2b-256 601d829047d07b5e95c99e1df4b8a10b92373d0ac3220b3ba1fa5a123778b85d

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