Chapter 3. Creating Testable Documentation with doctest

In this chapter, we will cover:

  • Documenting the basics
  • Catching stack traces
  • Running doctests from the command line
  • Coding a test harness for doctest
  • Filtering out test noise
  • Printing out all your documentation including a status report
  • Testing the edges
  • Testing corner cases by iteration
  • Getting nosy with doctest
  • Updating the project-level script to run this chapter's doctests

Introduction

Python provides the useful ability to embed comments inside functions that are accessible from a Python shell. These are known as docstrings.

A docstring provides the ability to embed not only information, but also code samples that are runnable.

There is an old adage that comments aren't code. Comments don't undergo syntax checks and are often not maintained, thus the information they carry can lose its value over time. doctest counters this by turning comments into code which can serve many useful purposes.

In this chapter, we will explore different ways to use doctest to develop testing, documentation, and project support. No special setup is required, as doctest is part of Python's standard libraries.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.144.56