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 explore how to write a custom nose plugin that provides results in a BDD-style report:

  1. Create a file called recipe26.py to contain our test cases.
  2. Create a unittest test, where the test case represents a cart with one item, and the test methods read like sentences:
import unittestfrom cart import *class CartWithOneItem(unittest.TestCase):      def setUp(self):          self.cart = ShoppingCart().add("tuna sandwich", 15.00)      def test_when_checking_the_size_should_be_one_based(self):          self.assertEquals(1, len(self.cart))      def test_when_looking_into_cart_should_be_one_based(self):          self.assertEquals("tuna sandwich", self.cart.item(1))          self.assertEquals(15.00, self.cart.price(1)) def test_total_should_have_in_sales_tax(self): ...

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