Skip to main content
http://gfxmonk.net/dist/status/project/pea.png

pea - The tiniest green vegetable.

pea is a minimal BDD framework for python, in the style of ruby’s cucumber and python’s lettuce. It aims to help you write the same kind of tests - but in straight-up python code, without all the parsing and indirection and other hoops to jump through. It’s a lot like ruby’s coulda.

Benefits of cucumber-style testing include:

  • You write your tests in clear, english language without inline code

  • Your tests are human-readable, and hopefully human-editable

  • You can re-use steps with confidence, because they all do exactly what they say on the tin

Benefits of pea over lettuce, cucumber, etc:

  • It’s a really trivial library (thus the name). It doesn’t do very much, so it probably doesn’t have many bugs

  • Your features are just python code:

    • No “BDD language parser” needed

    • No regular expressions

    • Stack traces make sense

    • Syntax highlighting

    • You can use ctags to jump between test & implementation, as well as for method completion

    • Managing and renaming functions is much easier than managing regexes

    • You can use whatever abstractions you like

    • You can use rich python objects as arguments, instead of parsing strings

  • It doesn’t need its own test runner; so you can just use nose to run it alongside your unit tests

So how do I use it?

Here’s a minimal example:

from pea import *

@step
def I_go_to_the_store():
        world.location='store'
        world.cart = []

@step
def I_buy_some(item):
        world.cart.append(item)

@step
def I_go_home():
        world.location = 'home'

@step
def I_have_some_delicious(item):
        assert item in world.cart
        world.assertEquals(world.location, 'home')

# --------------------

class TestShopping(TestCase):
        def test_buying_some_peas(self):

                Given.I_go_to_the_store()
                When.I_buy_some('peas')
                And.I_go_home()
                Then.I_have_some_delicious('peas')

… and when you run it (with nosetests, in verbose mode):

http://gfxmonk.net/dist/0install/impl/pea/screenshot.png

Typically you would put your steps in a separate python module (or many), but it’s your choice.

Basics:

  • @step adds your function to pea’s registry of steps, which allows them to be called via Given, When, And, and Then.

  • To re-use a step from inside another step, just call the function!

Stuff to remember:

  • Make sure you inherit from pea.TestCase (and call super from setUp/tearDown), as it takes care of resetting the world between tests.

  • You can use TestCase assertion methods on the world, too - e.g. world.assertEquals(expected, actual)

Pea works well with rednose

Metadata

Release files for pea 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pea 0.1.2
File Size Uploaded
pea-0.1.2.tar.gz 6.8 kB Details

Release files / pea-0.1.2.tar.gz

Download URL pea-0.1.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7a8501c07353eab0ba1c7207302f5fb63122312b5a02fa267dd500faa4e453bf
BLAKE2b-256 checksum
How to use checksums
eaff7ed8d00702e875abc29dbf90808359bb6830532593415c2c937bb024051f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page