Created
November 12, 2012 11:41
-
-
Save benhosmer/4058881 to your computer and use it in GitHub Desktop.
Using python doctests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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