O'Reilly logo

Python Testing Cookbook. by Bhaskar N. Das, 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

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, as shown here:
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 <cart.ShoppingCart object at ...>#the first item is a carton of milk >>> cart.item(1)'carton of milk'#the first price is $2.50 >>> cart.price(1)2.5#there is only one item >>> len(cart)This shopping cart lets us grab more than one of a particular item.#when we ...

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