Testing & Quality Assurance

behave

Write your tests as plain English sentences a manager could understand, and behave turns them into real automated checks.

Install it: pip install behave

What does it do?

Behave implements behaviour-driven development, a style of testing where you describe how a feature should work in structured, near-English sentences, like given a logged-in user, when they click checkout, then they should see an order confirmation, and connect those sentences to actual Python code that performs and checks each step. The plain-language description, called a scenario, becomes a living, executable specification that both technical and non-technical people on a team can read. Behind the scenes, each phrase triggers real Python functions that click buttons, check values, or call APIs.

See it in action

This is a plain-English description of a checkout scenario, saved in a special test file, that a companion Python program uses to automatically check the real checkout process works as described.

# features/checkout.feature
Feature: Checkout

  Scenario: Completing an order
    Given a logged-in user
    When they click checkout
    Then they should see an order confirmation

Why would a non-developer care?

A gap often exists between what a product manager thinks a feature should do and what a test actually verifies; behave narrows that gap by making the test itself readable by the people who aren’t writing the code. It’s a way of keeping does-this-feature-work honest and understandable across a whole team, not just the engineers.

Real-world examples

Behave is Python’s take on the behaviour-driven development style popularized in the Ruby world by a tool called Cucumber, and both use the same underlying Gherkin language for writing scenarios in structured plain English. Teams building customer-facing workflows, like checkout flows or signup processes, sometimes use it specifically so a non-engineer can review the actual test scenarios and confirm they match the intended business requirements.

Who uses it

Teams practicing behaviour-driven development who want tests that are readable and reviewable by non-engineers like product managers or QA specialists.

How it compares to alternatives

It’s Python’s equivalent to Cucumber, the Ruby tool that popularized this style of testing, and within Python it competes with a similar tool called pytest-bdd, which brings Gherkin-style scenarios into the pytest ecosystem instead of behave’s standalone runner.

Fun fact

Behave’s scenario format, Gherkin, gets its name from cucumbers, a joke carried over from Cucumber, the Ruby tool that started this whole style of testing.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries