Skip to main content

Agent for reporting Behave results to the ReportPortal

Project description

agent-python-behave

PyPI version PyPI pyversions CI codecov Join Slack chat! stackoverflow

Behave extension for reporting test results of Behave to the ReportPortal.

Usage

Installation

To install agent-python-behave run:

pip install behave-reportportal

You can find an example of integration with behave agent here. You can just copy this file to your features folder.

Configuration

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

behave -D config_file=<path_to_config_file>

The behave.ini file should have the following mandatory fields under [report_portal] section:

  • project - name of project in ReportPortal
  • endpoint - address of ReportPortal Server

Example of behave.ini:

[report_portal]
api_key = fb586627-32be-47dd-93c1-678873458a5f
endpoint = http://192.168.1.10:8080
project = user_personal
launch_name = AnyLaunchName
launch_attributes = Slow Smoke
launch_description = Smoke test

The following parameters are optional:

  • enabled = True - Enable / disable ReportPortal reporting.
  • api_key - value can be found in the User Profile section. Required if OAuth 2.0 is not configured.
  • oauth_uri = https://reportportal.example.com/uat/sso/oauth/token - OAuth 2.0 token endpoint URL for password grant authentication. Required if API key is not used.
  • oauth_username = my-username - OAuth 2.0 username for password grant authentication. Required if OAuth 2.0 is used.
  • oauth_password = my-password - OAuth 2.0 password for password grant authentication. Required if OAuth 2.0 is used.
  • oauth_client_id = client-id - OAuth 2.0 client identifier. Required if OAuth 2.0 is used.
  • oauth_client_secret = client-id-secret - OAuth 2.0 client secret.
  • oauth_scope = offline_access - OAuth 2.0 access token scope.
  • client_type = SYNC - Type of the under-the-hood ReportPortal client implementation. Possible values: [SYNC, ASYNC_THREAD, ASYNC_BATCHED].
  • launch_name = AnyLaunchName - launch name (default value is 'Python Behave Launch')
  • launch_uuid = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - UUID of the existing launch (the session will not handle the lifecycle of the given launch)
  • launch_attributes = Smoke Env:Python3 - list of attributes for launch
  • launch_description = Smoke test - launch description
  • debug_mode = True - creates the launch either as debug or default mode (defaults to False)
  • log_layout = Nested - responsible for Scenario, Step or Nested based logging (Scenario based approach is used by default)
  • is_skipped_an_issue = False - option to mark skipped tests as not 'To Investigate' items on Server side.
  • retries = 3 - amount of retries for performing REST calls to RP server
  • rerun = True - marks the launch as the rerun
  • rerun_of = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - launch id to rerun
  • launch_uuid_print = True - Enables printing Launch UUID on test run start. Default False.
  • launch_uuid_print_output = stderr - Launch UUID print output. Default stdout. Possible values: [stderr, stdout].
  • connect_timeout = 15 - Connection timeout to ReportPortal server. Default value is "10.0".
  • read_timeout = 15 - Response read timeout for ReportPortal connection. Default value is "10.0".
  • log_batch_size = 20 - maximum number of log entries which will be sent by the agent at once
  • log_batch_payload_limit = 65000000 - maximum payload size of a log batch which will be sent by the agent at once

If you would like to override the above parameters from command line, or from CI environment based on your build, then pass:

  • -D parameter=value during invocation.

Launching

To execute tests with ReportPortal run behave command and specify path to feature files:

behave ./tests/features

Test item attributes

Tag attribute can be used to specify attributes for features and scenarios. Attributes should be listed inside brackets of attribute tag separated by commas.

Example:

@attribute(key:value, value2)
@attribute(some_other_attribute)
Feature: feature name

    @attribute(key:value, value2, value3)
    Scenario: scenario name

Logging

For logging of the test item flow to ReportPortal, please, use the python logging handler and logger class provided by extension like below.

In environment.py:

import logging

from reportportal_client import RPLogger, RPLogHandler

from behave_reportportal.behave_agent import BehaveAgent, create_rp_service
from behave_reportportal.config import read_config


def before_all(context):
    cfg = read_config(context)
    context.rp_client = create_rp_service(cfg)
    context.rp_client.start()
    context.rp_agent = BehaveAgent(cfg, context.rp_client)
    context.rp_agent.start_launch(context)
    logging.setLoggerClass(RPLogger)
    log = logging.getLogger(__name__)
    log.setLevel("DEBUG")
    rph = RPLogHandler(rp_client=context.rp_client)
    log.addHandler(rph)
    context.log = log

Logger provides ability to attach some file in scope of log message (see examples below).

In steps:

@given("I want to calculate {number_a:d} and {number_b:d}")
def calculate_two_numbers(context, number_a, number_b):
    context.number_a = number_a
    context.number_b = number_b
    context.log.info("log message")

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

Test case ID

It's possible to mark some scenario with test_case_id(<some_id>) tag. ID specified in brackets will be sent to ReportPortal.

Integration with GA

ReportPortal is now supporting integrations with more than 15 test frameworks simultaneously. In order to define the most popular agents and plan the team workload accordingly, we are using Google analytics.

ReportPortal collects information about agent name and its version only. This information is sent to Google analytics on the launch start. Please help us to make our work effective. If you still want to switch Off Google analytics, please change env variable the way below.

export AGENT_NO_ANALYTICS=1

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

behave_reportportal-5.1.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

behave_reportportal-5.1.1-py2.py3-none-any.whl (16.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file behave_reportportal-5.1.1.tar.gz.

File metadata

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

File hashes

Hashes for behave_reportportal-5.1.1.tar.gz
Algorithm Hash digest
SHA256 25cebca7c1ccd8fe9577e2dcf238f17f7cb9674cc52cd2c2dc8352fff34b0d94
MD5 191defd022902771fd5459cc9da8d45a
BLAKE2b-256 fcadf92ecb3c43da452cd62b6cbde682c4524b97521cb9763edeb9d6551a5ca4

See more details on using hashes here.

File details

Details for the file behave_reportportal-5.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for behave_reportportal-5.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ef52976d7d794d816a8e78499dbcc5c139573bdc9d7645bffce9e24096cd515d
MD5 713b396977c314171f24301b8de730b4
BLAKE2b-256 6b210919e138bb0519936d304ee822f92459829d1e0273e4e40c99779d32a417

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