---
title: Pytest-BDD
description: Learn how to integrate Allure with Pytest-BDD to generate rich, interactive test reports. Follow step-by-step setup, test execution, and report generation guidance.
---

# Getting started with Allure Pytest-BDD

[![Allure Pytest-BDD pypi latest version](https://img.shields.io/pypi/v/allure-pytest-bdd?style=flat "Allure Pytest-BDD pypi latest version")](https://pypi.org/project/allure-pytest-bdd/)

Generate beautiful HTML reports using [Allure Report](https://allurereport.org/docs/) and your [Pytest-BDD](https://pytest-bdd.readthedocs.io/) tests.

## Setting up

### 1. Prepare your project

1. Install the Allure Report command-line tool, if it is not yet installed in your operating system. Note that Allure Report requires Java, see the [installation instructions](/docs/v2/install/).

1. Open a terminal and go to the project directory. For example:

   ```bash
   cd /home/user/myproject
   ```

1. If necessary for your system configuration, activate the virtual Python environment for your project.

   For example, if the project uses a `venv` environment, the command to activate it may look like this:

   ```bash
   source .venv/bin/activate
   ```

   This step is not necessary if you are using the system Python environment.

1. Install the Allure Pytest-BDD integration.

   ```bash
   pip install allure-pytest-bdd
   ```

### 2. Run tests

When running your tests, specify a path for the test results directory in the `--alluredir` command-line argument. For example:

```bash
python -m pytest --alluredir allure-results
```

This will save necessary data into the test results directory. If the directory already exists, the new files will be added to the existing ones, so that a future report will be based on them all.

### 3. Generate a report

Finally, convert the test results into an HTML report. This can be done by one of two commands:

- `allure generate` processes the test results and saves an HTML report into the `allure-report` directory. To view the report, use the `allure open` command.

- `allure serve` creates the same report as `allure generate`, then automatically opens the main page of the report in a web browser.

### Describe parametrized tests

Allure Pytest-BDD can display parameters passed to the tests via `Examples` tables, see the [reference](/docs/pytestbdd-reference/#parametrized-tests).

```gherkin
Feature: User management

  Scenario Outline: Registration
    When I go to the registration form
    And I enter my details: <login>, <password>, <name>, <birthday>
    Then the profile should be created

    Examples:
      | login   | password | name     | birthday   |
      | johndoe | qwerty   | John Doe | 1970-01-01 |
      | janedoe | 123456   | Jane Doe | 1111-11-11 |
```

## Attach screenshots and other files

You can [attach any sorts of files](/docs/attachments/) to your Allure report. For example, a popular way to make a report easier to understand is to attach a screenshot of the user interface at a certain point.

Allure Pytest-BDD provides various ways to create an attachment, both from existing files or generated dynamically, see the [reference](/docs/pytestbdd-reference/#attachments).

```python
import allure
import requests
from pytest_bdd import then

@then("I open labels page")
def test_labels():
    ...

    png_bytes = requests.get('https://example.com/image.png').content
    allure.attach(png_bytes, name="my-image", attachment_type=allure.attachment_type.PNG)

    allure.attach.file('/path/to/image.png', name="my-image", attachment_type=allure.attachment_type.PNG)
```

## Environment information

For the main page of the report, you can collect various information about the environment in which the tests were executed.

For example, it is a good idea to use this to remember the OS version and Python version. This may help the future reader investigate bugs that are reproducible only in some environments.

Images: /images/python/environment-allure3.png, /images/python/environment-allure2.png

To provide environment information, put a file named `environment.properties` into the `allure-results` directory after running the tests. See the example in [Environment file](/docs/how-it-works-environment-file/).

Note that this feature should be used for properties that do not change for all tests in the report. If you have properties that can be different for different tests, consider using [Parametrized tests](#describe-parametrized-tests).
