Created
February 7, 2023 18:16
-
-
Save jrgavilanes/799c1daf226fd28a8bd24608dd771041 to your computer and use it in GitHub Desktop.
python example of function with docstring that does selfcontained unit tests
This file contains hidden or 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
def suma(a: int = None, b: int = None) -> int: | |
""" sums two given integers | |
Args: | |
a: int | |
b: int | |
return: | |
int | |
>>> suma(2,4) | |
6 | |
>>> suma(2) | |
Traceback (most recent call last): | |
Exception: parameters are not given | |
>>> suma() | |
Traceback (most recent call last): | |
Exception: parameters are not given | |
""" | |
if not (a and b): | |
raise Exception("parameters are not given") | |
return a + b | |
************* | |
$ python -m doctest function.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment