python doctests


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def methodToTest(x):
  2. """
  3. >>> methodToTest(2)
  4. 1
  5. >>> methodToTest(0)
  6. Traceback (most recent call last):
  7. ...
  8. ZeroDivisionError: ...
  9.  
  10. >>> range(10)
  11. [0, 1, 2, ..., 9]
  12. """
  13. return 2/x
  14.  
  15.  
  16. if __name__ == "__main__":
  17. import doctest
  18. doctest.testmod(optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE)
  19. #doctest.testfile("example.txt")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.