How to Integrate Vedro with Allure
Tags: python, testing, vedro
Published: 2023-09-09 14:07:49

In modern software development, a comprehensive reporting tool is as crucial as the test cases themselves. [Allure](https://docs.qameta.io/allure/) has emerged as a highly flexible and insightful reporting tool that provides an in-depth look into what has been tested and what needs further attention. If you're using [Vedro](https://vedro.io), a pragmatic testing framework, integrating it with Allure can significantly enhance your test reporting capabilities.

## Laying the Groundwork

Before delving into the integration, ensure that you have Vedro installed:

```
pip install vedro
```

Consider the following simple Vedro scenario, which tests the retrieval of repositories for a GitHub user:

```python
import vedro
import httpx

class Scenario(vedro.Scenario):
    subject = "retrieve user repos"

    def given_user(self):
        self.user = "gvanrossum"

    def when_guest_retrieves_repos(self):
        self.response = httpx.get(f"https://api.github.com/users/{self.user}/repos")

    def then_it_should_return_a_successful_response(self):
        assert self.response.status_code == 200
```

Next, let's integrate this with Allure.

## Step 1: Install the Allure Plugin for Vedro

To get started with Allure in Vedro, first install the [Allure Reporter plugin](https://pypi.org/project/vedro-allure-reporter/):

```
vedro plugin install vedro-allure-reporter
```

## Step 2: Execute Tests and Generate Report Data

After installing the plugin, you can execute your tests and generate Allure report data:

```
vedro run -r rich allure
```

By default, this command saves the report data in the `./allure_reports` directory. To specify a different directory, use:

```
vedro run -r rich allure --allure-report-dir ./custom_allure_reports
```

## Step 3: Visualize the Report with the Allure CLI

To view the report, you'll need to install the Allure command-line tool first. Follow the installation instructions provided in the [official Allure guide](https://docs.qameta.io/allure/#_installing_a_commandline).

After you've installed the Allure CLI, serve the report:

```
allure serve ./allure_reports
```

This command will generate and open the report in your default web browser, providing a clear and interactive view of your test results.


![AllureScreenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygaj7sek4a7kfa4ow941.png)

## Enhance Reports Through Categorization and Labeling

To improve report visualization and understanding, consider labeling your tests. For example, label the previously defined scenario to categorize it under "GitHub API Testing":

```python
import vedro
from vedro_allure_reporter import allure_labels, Story, Epic, Feature

@allure_labels(Epic("GitHub API Testing"), Feature("User Repositories"))
class Scenario(vedro.Scenario):
    subject = "retrieve user repos"

    ...
```

Labeling is particularly useful when you have an extensive test suite and need to filter or group tests. For example, to run tests labeled under a specific epic, use:

```
vedro run --allure-labels epic="GitHub API Testing"
```

In summary, integrating Vedro with Allure not only enhances your testing workflow but also provides a comprehensive and interactive reporting experience, making it easier to track, filter, and understand your test results.