Saturday, 9 September 2017

Python Reporting || allure Reports + pytest

Allure Framework is a flexible lightweight multi-language test report tool gives beautiful reports for any programming language

Sample Code:
Sample.py

def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 5


Install required pytest, allure adaptor libraries via pip

pip install pytest
pip install pytest-allure-adaptor


First Step:
During test execution, a small library called adapter attached to the testing framework saves information about executed tests to XML files.

> pytest Sample.py -m alluredir G:\Dir1\

- Here xml files will be genarated.

Second Step:
During report generation, the XML files are transformed to a HTML report. This can be done with a command line tool.

Second Step/ Software setup:
download allure from here https://bintray.com/qameta/generic/allure2
unzip, and set Path variable to C:\Users\userName\Downloads\allure-2.3.5\bin;

open command window > allure --version
--o/p: 2.3.5

XML to HTML file conversion
open command window > allure serve G:\Dir1\

Thats all, Automatically allure report will be opened shown like below.








Python | pytest | Quick tutorail

Install Pytest:

open command window at

C:\Users\PK\AppData\Local\Programs\Python\Python36-32\Scripts

pytest --version

pip install -U pytest

-------------------------------

Our first test:

GoogleTest.py

def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 5

-------------------------------
Run:

open command window at C:\Users\PK\AppData\Local\Programs\Python\Python36-32\Scripts

pytest C:\Users\PK\PycharmProjects\allure-reports-with-pytest\tests\GoogleTest.py

or

>py.test -q -s GoogleTest.py