Git Product home page Git Product logo

agent-python-pytest's Introduction

agent-python-pytest

Important: this is draft version under development.

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

Usage

Installation

To install pytest plugin execute next command in a terminal:

pip install pytest-reportportal

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_tags = 'PyTest' 'Smoke'
rp_launch_description = 'Smoke test'
rp_ignore_errors = True

The following parapmeters are optional:

  • rp_launch = AnyLaunchName - launch name (could be overriden by pytest --rp-launch option, default value is 'Pytest Launch')
  • rp_launch_tags = 'PyTest' 'Smoke' - list of tags
  • rp_launch_description = 'Smoke test' - launch description
  • rp_log_batch_size = 20 - size of batch log request
  • rp_ignore_errors = True - Ignore Report Portal errors (exit otherwise)

Examples

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

import logging
# Import Report Portal logger and handler to the test module.
from pytest_reportportal import RPLogger, RPLogHandler
# Setting up a logging.
logging.setLoggerClass(RPLogger)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Create handler for Report Portal.
rp_handler = RPLogHandler()
# Set INFO level for Report Portal handler.
rp_handler.setLevel(logging.INFO)
# Add handler to the logger.
logger.addHandler(rp_handler)


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

    # Message with an attachment.
    import subprocess
    free_memory = subprocess.check_output("free -h".split())
    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.
    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 tags to Report Portal items. In the following example tags 'linux' and 'win32' will be used:

import pytest

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

Launching

To run test with Report Portal you can specify name of launch:

py.test ./tests --rp-launch AnyLaunchName

Copyright Notice

Licensed under the GPLv3 license (see the LICENSE file).

agent-python-pytest's People

Contributors

avarabyeu avatar frizzby avatar krasoffski avatar vakulich avatar

Watchers

 avatar

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.