GithubHelp home page GithubHelp logo

appian / agent-python-pytest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reportportal/agent-python-pytest

0.0 2.0 1.0 4.07 MB

Framework integration with PyTest

License: Apache License 2.0

Python 100.00%

agent-python-pytest's Introduction

agent-python-pytest

Pytest plugin for reporting test results of Pytest to the Reportal Portal.

  • Usage
  • Installation
  • Configuration
  • Contribution
  • Examples
  • Launching
  • Send attachement (screenshots)
  • Troubleshooting
  • Integration with GA
  • Copyright Notice

Usage

Installation

To install pytest plugin execute next command in a terminal:

pip install pytest-reportportal

IMPORTANT! The latest version does not support Report Portal versions below 5.0.0.

Specify the last one release of the client version 1 to install or update the client for other versions of Report Portal below 5.0.0:

pip install pytest-reportportal~=1.0

Contribution

All the fixes for the agent that supports Report Portal versions below 5.0.0 should go into the v1 branch. The master branch will store the code base for the agent for Report Portal versions 5 and above.

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_uuid - value could be found in the User Profile section
  • rp_project - name of project in Report Potal
  • rp_endpoint - address of Report Portal Server

Example of pytest.ini:

[pytest]
rp_uuid = 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_errors = True
rp_ignore_attributes = 'xfail' 'usefixture'
  • The rp_uuid can also be set with the environment variable RP_UUID. This will override the value set for rp_uuid in pytest.ini

The following parameters are optional:

  • rp_launch = AnyLaunchName - launch name (could be overridden by pytest --rp-launch option, default value is 'Pytest Launch')
  • rp_launch_attributes = 'PyTest' 'Smoke' 'Env:Python3' - list of attributes for launch
  • rp_tests_attributes = 'PyTest' 'Smoke' - list of attributes that will be added for each item in the launch
  • rp_launch_description = 'Smoke test' - launch description (could be overridden by pytest --rp-launch-description option, default value is '')
  • rp_log_batch_size = 20 - size of batch log request
  • rp_ignore_errors = True - Ignore Report Portal errors (exit otherwise)
  • rp_ignore_attributes = 'xfail' 'usefixture' - Ignore specified pytest markers
  • rp_hierarchy_dirs = True - Enables hierarchy for tests directories, default False. Doesn't support 'xdist' plugin.
  • rp_hierarchy_module = True - Enables hierarchy for module, default True. Doesn't support 'xdist' plugin.
  • rp_hierarchy_class = True - Enables hierarchy for class, default True. Doesn't support 'xdist' plugin.
  • rp_hierarchy_parametrize = True - Enables hierarchy parametrized tests, default False. Doesn't support 'xdist' plugin.
  • rp_hierarchy_dirs_level = 0 - Directory starting hierarchy level (from pytest.ini level) (default 0)
  • rp_issue_marks = 'xfail' 'issue' - Pytest marks that could be used to get issue information (id, type, reason)
  • rp_issue_system_url = http://bugzilla.some.com/show_bug.cgi?id={%issue_id} - issue URL (issue_id will be filled by parameter from pytest mark)
  • rp_issue_id_marks = True - Enables adding marks for issue ids (e.g. "issue:123456")
  • rp_verify_ssl = True - Verify SSL when connecting to the server
  • rp_display_suite_test_file = True In case of True, include the suite's relative file path in the launch name as a convention of "<RELATIVE_FILE_PATH>::<SUITE_NAME>". In case of False, set the launch name to be the suite name only - this flag is relevant only when "rp_hierarchy_module" flag is set to False

If you like to override the above parameters from command line, or from CI environment based on your build, then pass - -o "rp_launch_attributes=Smoke Tests" during invocation.

Examples

For logging of the test item flow to Report Portal, please, use the python logging handler provided by plugin like bellow: in conftest.py:

import logging
import sys

import pytest

from pytest_reportportal import RPLogger, RPLogHandler


@pytest.fixture(scope="session")
def rp_logger(request):
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    # Create handler for Report Portal if the service has been
    # configured and started.
    if hasattr(request.node.config, 'py_test_service'):
        # Import Report Portal logger and handler to the test module.
        logging.setLoggerClass(RPLogger)
        rp_handler = RPLogHandler(request.node.config.py_test_service)
        # Add additional handlers if it is necessary
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setLevel(logging.INFO)
        logger.addHandler(console_handler)
    else:
        rp_handler = logging.StreamHandler(sys.stdout)
    # Set INFO level for Report Portal handler.
    rp_handler.setLevel(logging.INFO)
    return logger

in tests:

# In this case only INFO messages will be sent to the Report Portal.
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 Report Portal.
    rp_logger.debug("Case1. Debug message")

Plugin can report doc-strings of tests as descriptions:

def test_one():
    """
    Description of the test case which will be sent to Report Portal
    """
    pass

Pytest markers will be attached as attributes to Report Portal items. In the following example attributes 'linux' and 'win32' will be used:

import pytest

@pytest.mark.win32
@pytest.mark.linux
def test_one():
    pass

If you don't want to attach specific markers, list them in rp_ignore_attributes parameter

Launching

To run test with Report Portal you must provide '--reportportal' flag:

py.test ./tests --reportportal

Test issue info

Some pytest marks could be used to specify information about skipped or failed test result. List of this marks should be specified in pytest ini file (see rp_issue_marks).

The following mark fields are used to get information about test issue:

  • issue_id - issue id (or list) in tracking system. This id will be added as comment to test fail result. If URL is specified in pytest ini file (see rp_issue_system_url), id will added as link to tracking system.
  • reason - some comment that will be added to test fail description.
  • issue_type - short name of RP issue type that should be assigned to failed or skipped test.

Example:

@pytest.mark.issue(issue_id="111111", reason="Some bug", issue_type="PB")
def test():
    assert False

Send attachement (screenshots)

https://github.com/reportportal/client-Python#send-attachement-screenshots

Troubleshooting

In case you have connectivity issues (or similar problems) with Report Portal, it's possible to ignore exceptions raised by pytest_reportportal plugin. For this, please, add following option to pytest.ini configuration file.

[pytest]
...
rp_ignore_errors = True

With option above all exceptions raised by Report Portal will be printed out to stderr without causing test failures.

If you would like to temporary disable integrations with Report Portal just deactivate pytest_reportportal plugin with command like:

py.test -p no:pytest_reportportal ./tests

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 ALLURE_NO_ANALYTICS=1

Copyright Notice

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.