skillfed

pytest-bdd

BDD for pytest

pytest-bdd v8.1.0 3.6M downloads/30d#2,558 on PyPI1,460
Permissive license MIT Active released

What it is and what it does

pytest-bdd is a pytest plugin that brings Gherkin-style behavior-driven development (BDD) testing into the pytest ecosystem. It lets you write human-readable feature files describing application behavior, then map those steps to Python test functions using decorators. Unlike standalone BDD tools, it integrates directly with pytest, so you can reuse pytest fixtures, combine BDD and unit tests in the same project, and avoid maintaining a separate test runner.

The package supports step parameters with multiple parser types (string, parse, cfparse, regex), step aliases for readability, and dependency injection through pytest fixtures. It handles the full BDD workflow—Given/When/Then steps, scenario outlines, and step argument parsing—while letting you leverage pytest's reporting, plugins, and configuration.

Use it for:

  • Write acceptance tests in plain Gherkin that non-technical stakeholders can read and understand.
  • Unify functional and unit tests in a single pytest suite, reducing test infrastructure complexity.
  • Reuse existing pytest fixtures as setup and action steps in BDD scenarios via dependency injection.
  • Parameterize BDD steps with multiple data types using parse or cfparse parsers for scenario coverage.
  • Maintain feature documentation that stays synchronized with executable tests.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

pytest-bdd implements Gherkin-based behavior-driven development testing within pytest, allowing you to write feature files and step definitions that unify functional and unit tests.

Yes. pytest-bdd is actively maintained, permissively licensed, has no known vulnerabilities, and integrates cleanly into pytest workflows. Install it if you need BDD-style testing, want to document requirements as executable scenarios, or need to bridge technical and non-technical stakeholders. The low install friction and mature codebase make it a safe choice for projects already using pytest.

Install

pytest-bdd on PyPI

pip

pip install pytest-bdd

uv

uv add pytest-bdd

poetry

poetry add pytest-bdd

Installing pytest-bdd

Before you install

Low install friction with a pure-Python wheel and seven runtime dependencies. The package is actively maintained with recent releases, 1460 repository stars, and support for modern Python versions (3.9–3.13).

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely in both open-source and commercial projects with minimal restrictions.

Quickstart

pip install pytest-bdd

from pytest_bdd import scenario, given, when, then

@scenario('example.feature', 'Example scenario')
def test_example():
    pass

@given('a precondition')
def precondition():
    return True

Requires Python 3.9 or later; feature files must follow Gherkin syntax and be discoverable by pytest.

Verify before relying

  • Whether the package's Gherkin subset covers the full range of Gherkin constructs needed for your project.
  • Performance characteristics when running large numbers of scenarios or with complex step definitions.
  • Integration compatibility with other pytest plugins beyond those listed as runtime dependencies.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 7 — Mako, gherkin-official, packaging, parse, parse-type, pytest, typing-extensions
Maintenance actively maintained — 617 days since the last release
Last repo commit
First released
Downloads 3,611,297/month — #2,558 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_bdd-8.1.0-py3-none-any.whl

Development Status :: 6 - MatureIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: TestingTopic :: Utilities

Tags

BDD testing frameworkGherkin pytest pluginbehavior driven developmentfeature file testingpytest BDD scenariosacceptance testing pytestgherkin language testing
bddgherkinacceptance-testing

More Libraries packages