10

I am using py test allure adaptor and trying to generate input data required for allure report. But I am not able to generate any XML's. When I execute the py file using py.test sample.py, it did create pycache dir. Then I executed "allure generate -v 1.3.9 C:\allurereports" (This is the dir where I had the sample.py). It did create an allure html report but no of test cases was 0. No details were present.

The sample.py(it is same as given in the example)

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

Here's the py.test command used: py.test sample.py --allure_features=feature1,feature2

Can anybody help me how to generate an allure report from the file? What are the commands to execute?

Lavanya
  • 101
  • 1
  • 1
  • 3

5 Answers5

18

Lavanya. I'll try to explain the sequence you must to perform to generate allure report of autotest.

  1. Install pip. Download get-pip.py and perform python get-pip.py.

  2. Install pytest and pytest-allure-adaptor via pip. Perform python -m pip install pytest allure-pytest

  3. Generate autotest allure xml report. Perform python -m pytest sample.py --alluredir <some directory>

  4. In <some directory> appear xml autotest report, which contain results of sample.py tests. Let's make beauty html report via an allure-cli tool.

  5. Install allure-cli. Download last version of allure-cli. allure-cli requires java. allure-cli doesn't require installation, just unpack and use it.

  6. Generate html report. Find allure (allure.bat for Windows) in unpacked zip. Perform allure.bat generate -o <some directory> -v 1.4.0 <some directory>

  7. Find index.html in <some directory> and open it via a browser.

*Note <some directory> the same for all steps

BioGeek
  • 21,897
  • 23
  • 83
  • 145
  • 3
    I've encounter some problems while installing package `pytest-allure-adaptor`. It depends on `lxml` and the last one is automatically installed first. See [Requires Distributions](https://pypi.python.org/pypi/pytest-allure-adaptor) to get dependencies. Namely, `lxml` installation caused problems. Installation of packages `libxml2-dev` and `libxslt1-dev` into my system, according to [this](http://stackoverflow.com/questions/13019942/why-cant-i-get-pip-install-lxml-to-work-within-a-virtualenv) and [this](http://stackoverflow.com/questions/5178416/pip-install-lxml-error), solved the problem. – Andriy Jan 13 '16 at 16:01
  • 1
    pytest-allure-adaptor is deprecated and will not work on python 3.10, use allure-pytest instead. – MortenB Apr 29 '22 at 13:58
4

There is a very simple way to generate reports via allure:

first, install allure:

  1. allure-pytest 2.6.0
  2. allure-python-commons 2.6.0

Then, if you are unable to generate the reports, follow below steps:

  1. (using pytest)

    pytest test_xyz.py --alluredir=path_where_you_want_to_save_reports
    
  2. allure serve report_path
    

If it is still showing allure is not recognized command (blah -blah), then install allure using npm plugin with below command:

npm install -g allure-commandline --save-dev

then follow step (2) again, then one server will start and you will be able to see allure reports.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
jayesh
  • 3,277
  • 1
  • 18
  • 7
  • I am trying to generate report with allure-commons instead of Pytest. Can you please share the command for the same to create the XML & Json allure report files? – Harish Kannan Nov 25 '20 at 13:41
1

You should specify directory with your test data (the directory which contains -testsuite.xml files), not a test directory.

You can use py.test --alluredir [path_to_report_dir] to specify it.

PS. Make sure you use right version of allure (latest pytest adapter supports only allure 1.4.*).

For more information see https://github.com/allure-framework/allure-python and https://github.com/allure-framework/allure-cli

BioGeek
  • 21,897
  • 23
  • 83
  • 145
Dmitry Baev
  • 2,270
  • 1
  • 14
  • 24
1

This is something that I found working -

python3 -m pytest [your_test_class_name] --alluredir \Report

Then perform the below line where you saved your report -

python3 -m allure serve \Report

This will open up the allure report in your default browser.

adiga
  • 34,372
  • 9
  • 61
  • 83
Shivam Bharadwaj
  • 1,864
  • 21
  • 23
0

now you must use allure-command-line instead of allure-cli to generate html-report, cause the second one is deprecated.

Ustin
  • 568
  • 6
  • 19