Skip to main content
http://img.shields.io/pypi/v/pytest-bdd-ng.svg https://codecov.io/gh/elchupanebrej/pytest-bdd-ng/branch/default/graph/badge.svg Documentation Status https://badgen.net/badge/stand%20with/UKRAINE/?color=0057B8&labelColor=FFD700

pytest-bdd-ng combine descriptive clarity of Gherkin language with power and fullness of pytest infrastructure. It enables unifying unit and functional tests, reduces the burden of continuous integration server configuration and allows the reuse of test setups.

Pytest fixtures written for unit tests can be reused for setup and actions mentioned in feature steps with dependency injection. This allows a true BDD just-enough specification of the requirements without obligatory maintaining any context object containing the side effects of Gherkin imperative declarations.

Why NG ?

The current pytest plugin for cucumber is pytest-bdd , a popular project with 1.2k stars and used in 3k public repos and maintained by the pytest community. The upstream open-cucumber project does not have an official python release, so the current cucumber specs include features not available in pytest-bdd . This project is an effort to bridge the gap and also make it easier for pytest users to access new cucumber features.

Feature

original

NG

Description

Official parser support

-

+

All features of Feature files are supported from the “box” (localisation, Rules, Examples, Data tables, etc.)

Steps definitions via Cucumber expressions

-

+

Easy migration between implementations

Reporting using Messages

-

+

Possible to use all collection of Cucumber community tools for reporting

Pickles internal protocol

-

+

Allows to implement parsers based on other file types/principles

Heuristic step matching

-/+

+

Steps ease of use / amount of needed boilerplate code

Step execution context. Step types and variants of definition

-/+

+

Dispatching steps by kind. Steps injecting multiple fixtures. Default injecting behaviors. Steps could be used on import automatically. It’s possible to define default values for step variables.

Automatic collection of Feature files

-

+

No boilerplate code / No mix between steps definition and feature files

Load of Feature files by HTTP

-

+

Allows to integrate the library into external Feature storages

Stability and bugfixes

+

+/-

Supported python/pytest versions

+/-

+

NG supports wider and elder pytest&python version. Tested also for PyPy

Active community

+

-/+

Install pytest-bdd-ng

pip install pytest-bdd-ng

Packages for parsing Markdown defined features

npm install @cucumber/gherkin

Packages for reporting

npm install @cucumber/html-formatter

TLDR;

Feature: Simplest example
  Scenario:
    # https://cucumber.io/docs/gherkin/reference/
    Given File "Passing.feature" with content:
      """gherkin
      Feature: Passing feature
        Scenario: Passing scenario
          * Passing step
      """
    # https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
    And File "conftest.py" with content:
      """python
      from pytest_bdd import step

      @step('Passing step')
      def _():
        ...
      """
    # https://docs.pytest.org/en/stable/how-to/usage.html
    When run pytest
    Then pytest outcome must contain tests with statuses:
      |passed|
      |     1|

Project layout

pytest-bdd-ng automatically collects *.feature files from pytest tests directory. Important to remember, that feature files are used by other team members as live documentation, so it’s not a very good idea to mix documentation and test code.

The more features and scenarios you have, the more important becomes the question about their organization. So the recommended way is to organize your feature files in the folders by semantic groups:

features
├──frontend
│  └──auth
│     └──login.feature
└──backend
   └──auth
      └──login.feature

And tests for these features would be organized in the following manner:

tests
└──conftest.py
└──functional
│     └──__init__.py
│     └──conftest.py
│     │     └── "User step library used by descendant tests"
│     │
│     │         from steps.auth.given import *
│     │         from steps.auth.when import *
│     │         from steps.auth.then import *
│     │
│     │         from steps.order.given import *
│     │         from steps.order.when import *
│     │         from steps.order.then import *
│     │
│     │         from steps.browser.given import *
│     │         from steps.browser.when import *
│     │         from steps.browser.then import *
│     │
│     └──frontend_auth.feature -> ../../features/frontend/auth.feature
│     └──backend_auth.feature -> ../../features/backend/auth.feature
...

The step definitions would then be organized like this:

steps
└──auth
│     └── given.py
│     │      └── """User auth step definitions"""
│     │          from pytest import fixture
│     │          from pytest_bdd import given, when, then, step
│     │
│     │          @fixture
│     │          def credentials():
│     │             return 'test_login', 'test_very_secure_pass'
│     │
│     │          @given('User login into application')
│     │          def user_login(credentials):
│     │             ...
│     └── when.py
│     └── then.py
└──order
│     └── given.py
│     └── when.py
│     └── then.py
└──browser
│     └── ...
...

To make links between feature files at features directory and test directory there are few options (for more information please examine the project’s tests):

  1. Symlinks

  2. .desktop files

  3. .webloc files

  4. .url files

How to Contribute

The project is now open to contributions. Please open an issue for more details.

Release files for pytest-bdd-ng 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-bdd-ng 2.3.1
File Size Uploaded
pytest_bdd_ng-2.3.1.tar.gz 64.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-bdd-ng 2.3.1
File Interpreter ABI Platform
pytest_bdd_ng-2.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 138.3 kB

Release files / pytest_bdd_ng-2.3.1.tar.gz

Download URL pytest_bdd_ng-2.3.1.tar.gz
Size 64.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d35f410771fb63b579130230d3becb2e323aa3114cb32a981eaffce624140704
BLAKE2b-256 checksum
How to use checksums
71048f5881fdb5a8b29d97311f2ebf343d53b63609beadb5548b12314c02df34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / pytest_bdd_ng-2.3.1-py3-none-any.whl

Download URL pytest_bdd_ng-2.3.1-py3-none-any.whl
Size 74.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ea24a53b62d7d69b58da4893d2d72b8432962dfa0279355131d6c2c020990f8
BLAKE2b-256 checksum
How to use checksums
fd217ea5b535c1a5373aa25e5d5748f012473503b8cf2fa1f4a9c9a7c35659ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

2.3.1 This release

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page