Posted By

manatlan on 10/21/09


Tagged

python tech unittests


Versions (?)

python doctests


 / Published in: Python
 

  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  

You need to login to post a comment.