Skip to main content


Project description


Library to convert BDD features into Python unittest.TestCase classes. Run the tests with your favorite test runner, like pytest, unittest or nose. See the demo folder for an example.


Let’s take a calculator as an example. Create a plain text file called calculator.feature containing the BDD-style feature description:

Feature: Basic math operations
 Test addition

Scenario: add
 Given the value 10
 When adding 7
 Then the result is 17

Scenario: add a negative value
 Given the value 19
 When adding -11
 Then the result is 8

This is the text you can discuss with the customer and agree on. Next write a backing file called containing the code to run this feature:

import os
from bdd import Environment
from calculator import Calculator

env = Environment()
env.context.calculator = Calculator()

@env.given('the value {:d}')
def step(context, value):
    context.calculator.value = value

@env.when('adding {:d}')
def step(context, value):

@env.then('the result is {:d}')
def step(context, value):
    assert context.calculator.value == value

def rel(p):
    this_dir = os.path.dirname(os.path.abspath(__file__))
    return os.path.join(this_dir, p)

CalculatorTestCase = env.load_feature_as_testcase('calculator.feature')

Finally, write the actual production code to implement the calculator, in a file called

class Calculator:
    def __init__(self):
        self.value = 0

    def add(self, value):
        self.value += value

Now run the tests with, for example, pytest:

$ python -m pytest -v
=========== test session starts ===========================
platform linux -- Python 3.5.1, pytest-2.9.1
collected 2 items <- PASSED <- PASSED


A really good python bdd library is behave.



  • Add tag support

0.1 (Jun 2, 2016)

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (4.6 kB view hashes)

Uploaded Source

Built Distribution

bdd-0.2-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page