Skip to content

Instantly share code, notes, and snippets.

@eak24
Created March 6, 2018 20:37
Show Gist options
  • Save eak24/bdb61ccdf352e1fbf560e80dc5ee4481 to your computer and use it in GitHub Desktop.
Save eak24/bdb61ccdf352e1fbf560e80dc5ee4481 to your computer and use it in GitHub Desktop.
Doc string tests
def add(a, b):
"""
This is a function that implements adding
>>> from aide_design.play import *
>>> import math
>>> add(5, 10)
15
>>> add(25*u.m,5*u.m)
30 meter
>>> np.sqrt(2)
1.414213562373095
"""
return a+b
import doctest
doctest.testmod(verbose=True)
@eak24
Copy link
Author

eak24 commented Mar 6, 2018

This is an example of how to include tests within your code. These tests can be run by running the final two lines of code. It is best practice to include these examples/tests within your code. They help communicate how to use your library AND they can be used for regression testing AND they can be used for test driven development. Here's a video going into a bit more detail. And here is the FULL documentation on doctest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment