top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

Mom's Guide to Behave (Python Behaviour Driven Development)

May 21, 2025
2 min read

Updated: May 22, 2025




“Understanding Python Behave with clarity and care — just like mom would explain.Because even moms can teach BDD — the Pythonic way!”
“Understanding Python Behave with clarity and care — just like mom would explain.Because even moms can teach BDD — the Pythonic way!”

Behave is Python’s BDD framework that turns user stories into testable scenarios. Let’s break it down—Mom style!


What is Behave?

Consider Behave as a cookbook for testing your software. Similar to following a recipe to bake cookies, Behave allows you to write tests in simple language that outline how your software is expected to function. Behave is written in plain English,coded in python.Behave is like mom saying: ‘Sure, you can go out...’ But Python is quietly running checks on your location, money, and grades."



The Key Ingredients

  1. Feature files: They are like Mom's recipe cards

    1. Neatly written in plain English(Gherkins Language).

    2. Easy to follow.


    Ghekin's Cheat Sheet

Gherkin's Keyword

What Does it do?

Mom's Example

Feature

Describes what you are testing ?

Feature: Grocery Budget Management

Background

Common setup for all scenarios

Given I have $1000; And rent is paid

Scenario

A specific case or test example

Scenario: Buying veggies under budget

Given

Pre-condition or starting state

Given I have $200

When

The action you're testing

When I spend $150 on groceries.

Then

The expected result

Then I should be left with $50(hopefully!)

And/But

Add more steps to any part

And I buy milk; But I return the chips

@Tags

Labels or groups scenarios

@groceries, @rent, @utilities

Scenario Outline

Template to run the same test with different data



Guidelines for Writing Feature Files

  1. Ensure all your feature files have a .feature extension - Just like every recipe needs a label!"

  2. Begin with a Feature Title "Mark your jar before adding money!"

  3. Craft Scenarios as Short Stories "Each dollar spent should tell a tale!"

  4. Adopt Declarative Steps (Avoid Imperative) "Mom says what should happen, not how to do it!"

  5. Utilize Background for Common Setup "Use Background like a family rule—establish it once, and let all scenarios adhere to it (unless an exception is needed)!"

  6. Tag Scenarios for Organization."Label your money envelopes—savings, spending, emergencies!"



Sample Feature File
Sample Feature File


  1. Step Definitions - These are the actual Python code that makes the steps work.Like the actual cooking instructions behind the recipe.


    Guidelines for Writing Step definitions

    1. Match the Gherkin Steps Exactly ."If the recipe says ‘1 cup sugar,’ don’t use salt!"

    2.Use context to Share Data to use across steps."Like passing the grocery list between family members!"

    3. Keep Steps Atomic (One Action per Step)."One chore at a time—no multitasking!"

    4.Use Parameters {}for Flexibility."A good budget works with any number!"

    5.Address Assertions Transparently."Verify the receipt before exiting the store!"







Why Use Behave?

  1. Clear instructions (no vague "pinch of salt" here!).


  1. Collaboration (even non-techies can read Gherkin!).


  1. Predictable results (no burnt cookies!).


Moms love comparing to get the best!

Tool

Mom's Verdict

Behave

"Easy-to-read recipes!" (Gherkin)

pytest

"Too technical—no stories!"

unittest

"Where’s the flavor?!"

Hungry for more? Check out:

Behave Documentation

Selenium for Python Documentation

GitHub Repo with a project with Python Behave BDD



 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page