Skip to content

python tests with regex


  • touch features/users.features
Feature: Users

  Scenario: Add users
    Given the following users
      | name  | email              | password |
      | Alice | | secret   |
      | Bob   |   | password |
    When I enter the email ""
    Then the user should be in the list
  • touch features/steps/
from behave import *

@given('the following users')
def step_impl(context):
    for row in context.table:
        name = row['name']
        email = row['email']
        password = row['password']
        context.users.append({'name': name, 'email': email, 'password': password})

@when('I enter the email "{email}"')
def step_impl(context, email): = email

@then('the user should be in the list')
def step_impl(context):
    for user in context.users:
        if user['email'] ==
    assert False, f"User with email '{}' not found"


  • requirements.txt
Feature: Greeting

  Scenario: Greet the user by name
    When I enter the name "Alice"
    Then the greeting should say "Hello, Alice!"

  Scenario: Greet the user with a different name
    When I enter the name "Bob"
    Then the greeting should say "Hello, Bob!"
from behave import *

@when('I enter the name "{name}"')
def step_impl(context, name): = name

@then('the greeting should say "{greeting}"')
def step_impl(context, greeting):
    assert f"Hello, {}!" == greeting