Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created November 12, 2012 11:41
Show Gist options
  • Save benhosmer/4058881 to your computer and use it in GitHub Desktop.
Save benhosmer/4058881 to your computer and use it in GitHub Desktop.
Using python doctests.
"""
An example of using doctest to automatically test.
One function that adds items together.
>>> adder(1,2)
3
"""
def adder(x,y):
"""Return the result of adding x and y
>>> adder(1,2)
3
>>> adder(a,b)
Traceback (most recent call last):
...
NameError: name 'a' is not defined
>>> adder("a","b")
'ab'
"""
result = x + y
return result
if __name__ == "__main__":
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment