O'Reilly logo

Python Testing Cookbook by Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a testable story with doctest

Capturing a succinct story in a doctest file is the key to BDD. Another aspect of BDD is providing a readable report including the results.

Getting ready

For this recipe, we will be using the shopping cart application shown at the beginning of this chapter.

How to do it...

With the following steps, we will see how to write a custom doctest runner to make our own report.

  1. Create a new file called recipe28_cart_with_no_items.doctest to contain our doctest scenario.
  2. Create a doctest scenario that exercises the shopping cart.
    This scenario demonstrates a testable story. First, we need to import the modules >>> from cart import * >>> cart = ShoppingCart() #when we add an item >>> cart.add("carton of milk", 2.50) #doctest:+ELLIPSIS ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required