Skip to main content

Allure Pytest Adaptor

Join the chat at https://gitter.im/allure-framework/allure-core 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, ISSUE-3 and ISSUE-4 label
    @allure.issue('http://jira.lan/browse/ISSUE-3')
    def test_bar1(self):
        # You can use this feature like a function inside the test
        allure.dynamic_issue('http://jira.lan/browse/ISSUE-4')
        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.

Release files for pytest-allure-adaptor 1.7.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-allure-adaptor 1.7.10
File Size Uploaded
pytest-allure-adaptor-1.7.10.tar.gz 16.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pytest-allure-adaptor 1.7.10
File Interpreter ABI Platform
pytest_allure_adaptor-1.7.10-py3-none-any.whl Python 3 none any Details
pytest_allure_adaptor-1.7.10-py2-none-any.whl Python 2 none any Details

Total release size: 59.3 kB

Release files / pytest-allure-adaptor-1.7.10.tar.gz

Download URL pytest-allure-adaptor-1.7.10.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
efd2d642c3f4be8333edbef44301c8596efb0aeb264b29baa4cf9bd35c1210aa
BLAKE2b-256 checksum
How to use checksums
eb2febfd6a52009bb631408c15ee3922c14f51347186986378314e5488164c94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_allure_adaptor-1.7.10-py3-none-any.whl

Download URL pytest_allure_adaptor-1.7.10-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28e7fa180af24a0e230667366b2ed9fd27e0d9f81df046f4aaae980d6d1f077b
BLAKE2b-256 checksum
How to use checksums
2e94862ca2f86f3644fd6687e254518ff57fe729676172ef37594913e88a2e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_allure_adaptor-1.7.10-py2-none-any.whl

Download URL pytest_allure_adaptor-1.7.10-py2-none-any.whl
Size 21.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
1470214bc622d6aa62257e6250c8fbc890f97227d24a38a2f1445e993fd4f9e3
BLAKE2b-256 checksum
How to use checksums
385b5f8ff6092fb96785927dcde5f554354ed50f85f577ae31b27f0f849ae554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.7.10 This release

3 release files

1.7.9

3 release files

1.7.8

3 release files

1.7.7

2 release files

1.7.6

2 release files

1.7.5

3 release files

1.7.4

2 release files

1.7.3

2 release files

1.7.2

3 release files

1.7.1

3 release files

1.7.0

3 release files

1.6.8

3 release files

1.6.7

1 release file

1.6.6

1 release file

1.6.5

1 release file

1.6.4

1 release file

1.6.3

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.4

1 release file

1.5.3

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.9

1 release file

1.3.8

1 release file

1.3.7

1 release file

1.3.6

1 release file

1.3.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page