Skip to main content

Plugin for py.test to generate allure xml reports

Project description

Allure Pytest Adaptor

Join the chat at https://gitter.im/allure-framework/allure-python Build Status Release Status Downloads

This repository contains a plugin for py.test which automatically prepares input data used to generate Allure Report. Note: this plugin currently supports only Allure 1.4.x series.

Installation and Usage

py.test --alluredir [path_to_report_dir]
# WARNING [path_to_report_dir] will be purged at first run

This plugin gets automatically connected to py.test via entry point if installed.

Connecting to IDE:

pytest_plugins = 'allure.pytest_plugin',\

Allure Features

Attachments

To attach some content to test report:

import allure

def test_foo():
    allure.attach('my attach', 'Hello, World')

Steps

To divide a test into steps:

import pytest

def test_foo():
    with pytest.allure.step('step one'):
        # do stuff

    with pytest.allure.step('step two'):
        # do more stuff

Can also be used as decorators. By default step name is generated from method name:

import pytest

@pytest.allure.step
def make_test_data_foo():
    # do stuff

def test_foo():
    assert make_some_data_foo() is not None

@pytest.allure.step('make_some_data_foo')
def make_some_data_bar():
    # do another stuff

def test_bar():
    assert make_some_data_bar() is not None

Steps can also be used without pytest. In that case instead of pytest.allure.step simply use allure.step:

import allure

@allure.step('some operation')
def do_operation():
    # do stuff

allure.step decorator supports step name formatting with function parameters:

import allure

@allure.step('some operation for bar={0}')
def do_operation(bar):
    # do stuff

def test_foo():
    assert do_operation('abcdef')

The step in the latter case will have name some operation for bar=abcdef. Formatting is done via python’s built-in string.format and supports it’s options. Arguments are passed to format method in the same way they are passed to the decorated function.

Steps support is limited when used with fixtures.

Severity

Any test, class or module can be marked with different severity:

import pytest

@pytest.allure.severity(pytest.allure.severity_level.MINOR)
def test_minor():
    assert False


@pytest.allure.severity(pytest.allure.severity_level.CRITICAL)
class TestBar:

    # will have CRITICAL priority
    def test_bar(self):
        pass

    # will have BLOCKER priority via a short-cut decorator
    @pytest.allure.BLOCKER
    def test_bar(self):
        pass

To run tests with concrete priority:

py.test my_tests/ --allure_severities=critical,blocker

Issues

Issues can be set for test.

import pytest

@pytest.allure.issue('http://jira.lan/browse/ISSUE-1')
def test_foo():
    assert False


import allure

@allure.issue('http://jira.lan/browse/ISSUE-2')
class TestBar:

    # test will have ISSUE-2 and ISSUE-3 label
    @allure.issue('http://jira.lan/browse/ISSUE-3')
    def test_bar1(self):
        pass

    # test will have only ISSUE-2 label
    def test_bar2(self):
        pass

Test cases

Test cases links can be set for test also.

import pytest

@pytest.allure.testcase('http://my.tms.org/TESTCASE-1')
def test_foo():
    assert False


import allure

@allure.testcase('http://my.tms.org/browse/TESTCASE-2')
class TestBar:

    # test will have TESTCASE-2 and TESTCASE-3 label
    @allure.testcase('TESTCASE-3')
    def test_bar1(self):
        pass

    # test will have only TESTCASE-2 label
    def test_bar2(self):
        pass

Features & Stories

Feature and Story can be set for test.

import allure


@allure.feature('Feature1')
@allure.story('Story1')
def test_minor():
    assert False


@allure.feature('Feature2')
@allure.story('Story2', 'Story3')
@allure.story('Story4')
class TestBar:

    # will have 'Feature2 and Story2 and Story3 and Story4'
    def test_bar(self):
        pass

To run tests by Feature or Story:

py.test my_tests/ --allure_features=feature1,feature2
py.test my_tests/ --allure_features=feature1,feature2 --allure_stories=story1,story2

Environment Parameters

You can provide test environment parameters such as report name, browser or test server address to allure test report.

import allure
import pytest


def pytest_configure(config):
    allure.environment(report='Allure report', browser=u'Я.Браузер')


@pytest.fixture(scope="session")
def app_host_name():
    host_name = "my.host.local"
    allure.environment(hostname=host_name)
    return host_name


@pytest.mark.parametrize('country', ('USA', 'Germany', u'Россия', u'Япония'))
def test_minor(country):
    allure.environment(country=country)
    assert country

More details about allure environment you can know from documentation.

Development

Use allure.common.AllureImpl class to bind your logic to this adapter.

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-allure-adaptor-1.7.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distributions

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

pytest_allure_adaptor-1.7.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

pytest_allure_adaptor-1.7.0-py2-none-any.whl (20.7 kB view details)

Uploaded Python 2

File details

Details for the file pytest-allure-adaptor-1.7.0.tar.gz.

File metadata

File hashes

Hashes for pytest-allure-adaptor-1.7.0.tar.gz
Algorithm Hash digest
SHA256 809a36f838e7ff8f849198e4b30df05e7702b4eaad59e723db21dc485f71756a
MD5 6c109a1db082c43500dd670f68e166f8
BLAKE2b-256 d9ba0a43ad58727884993d2d5dfaabb5d762a6c772ededb0e0a0fef5ae48da8f

See more details on using hashes here.

File details

Details for the file pytest_allure_adaptor-1.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_allure_adaptor-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4252193fcfba81d213bd02e70212cd8bf18b415c42948197b4411bc259191c
MD5 a5f465f2509f1108022dd78928bb55ea
BLAKE2b-256 480fa141ea11475f0dc5d598235e0a5f36c78c86297804f90ddec147069aa004

See more details on using hashes here.

File details

Details for the file pytest_allure_adaptor-1.7.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pytest_allure_adaptor-1.7.0-py2-none-any.whl
Algorithm Hash digest
SHA256 e972cb0a41fe82532540eac741c36c171fff80837d87d336dc2110c7e5075e5f
MD5 d4974940d0bda92ff4552f294a7b9ce4
BLAKE2b-256 4ba1a056d2cbe09ab398be7b0ebeb303464ffdcc83d42cbcfd968004591d6c59

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