Setting allure report with Python. For creating beautiful html report for your Python project.
About Allure reports:
The reports are the actual thing viewed by client or end-users. Report alone can make big difference for you. When writing automation testcases we dont have much options for making reports. Unit-test provide report, htmlreportgenerator is the other utility. But these options became average when I came accross Allure. But when I tried to use it then it became very challenging as the documentation is not good for python related things. Also there were lot of compatibility issues when allure used with pytest adaptors.Finally I was able to create report using allure. Now I will tell you from scratch how can we use Allure reports with python projects or simple scripts...
The main problem which prevent from running allure is the version number of allure-adapter, pytest with python 2.7. For using allure for python3 a different version of allure should be installed.
To install allure for generating the report using python2.7 follow the steps given below:
step1: pip install pytest pytest-allure-adaptor
step2: install wheel
python -m pip install wheel
step3: download lxml-3.4.1.win32-py2.7 from the below link
https://pypi.python.org/pypi/lxml/3.4.1#downloads
Its an .exe file,copy it to c:/Python27 directory and install the same
step4: pip install pytest pytest-allure-adaptor
Get the right adaptor mostly 1.4.0 will work and
download pytest-allure-adaptor-1.4.0.tar.gz (md5) from below
https://pypi.python.org/pypi/pytest-allure-adaptor/1.4.0 and
paste in the folder below
C:\Python27\Lib\site-packages
step5: Download the Allure commandline from
https://github.com/allure-framework/allure2
Click on Clone or download which will download the .zip file like allure-commandline
copy the Allure directory, unzip (which contains lib,plugins,bin folders) in my C:\ drive where ever you want use
Step-6 In the path command set the allure path to the location where allure.bat is present. For eg:
set path = c:\allure\bin
After this u will be able to run allure command from any location in cmd prompt.
Now generate the report using below steps:
1) Run py.test as shown below
py.test --alluredir Testdir script.py
py.test --alluredir <name_of_the_directory> <script_name>
This will generate pycache folder and it strore a xml report in the folder. This can now be converted to beautifull allure report.
Sometime on running the above command it will give error "program file/java/jdk1.8" etc. Then just remove the java_path and jre_path from the path and rerun the command.
2) Generate the report using Allure.bat Note that use the .bat present in allure directory not the other as shown below.
$ allure\bin\allure.bat generate ultimatedir -o report_ultimatedir
$ allure generate directory-with-results/ -o directory-with-report
Eg of how the final allure report will look...
For any queries you are welcome to add comments...
No comments:
Post a Comment