Package-level doctests

As we have seen so far, doctests can be written for methods, classes, and modules. However, they can also be written for whole packages. Typically, these would be put in the __init__.py file of the package and would show how the package as a whole should work, including multiple interacting classes. Here is one such set of doctests from our __init__.py file:

r""" The stock_alerter module allows you to set up rules and get alerted when those rules are met. >>> from datetime import datetime First, we need to setup an exchange that contains all the stocks that are going to be processed. A simple dictionary will do. >>> from stock_alerter.stock import Stock >>> exchange = {"GOOG": Stock("GOOG"), "AAPL": Stock("AAPL")} Next, we ...

Get Test-Driven Python Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.