pytest-bdd
BDD for pytest
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-bdduv
uv add pytest-bddpoetry
poetry add pytest-bddInstalling 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
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
behavebehave is a behavior-driven development (BDD)…
permissive · top 5,000 on PyPI
radish-bddradish is a Behavior Driven Development (BDD)…
permissive · top 15,000 on PyPI
vedroVedro is a scenario-style testing framework for…
permissive · top 15,000 on PyPI
terraform-complianceterraform-compliance is a BDD-based test…
permissive · top 15,000 on PyPI
behave-djangoIntegrates Behave BDD testing into Django…
permissive · top 15,000 on PyPI
gherkin-officialParses and compiles Gherkin feature files into…
permissive · top 5,000 on PyPI
cucumber-expressionsCucumber Expressions provides a simpler, more…
permissive · top 5,000 on PyPI
cucumber-tag-expressionsParses and evaluates boolean tag expressions…
permissive · top 5,000 on PyPI
allure-pytest-bddIntegrates Allure Report with Pytest-BDD to…
permissive · top 15,000 on PyPI
behavexBehaveX extends Behave with parallel test…
unclear · top 15,000 on PyPI