Testing with doctest - up1/course-python-workshop GitHub Wiki
Testing with doctest
File demo.py
import doctest
"""
Say hi to a person.
>>> say_hi("Somkiat")
Hi, Somkiat!
"""
def say_hi(name: str) -> str:
"""
Print a greeting message with the provided name.
Args:
name (str): The name to greet.
"""
return f"Hi, {name}!"
if __name__ == "__main__":
doctest.testmod() # Run the doctests in this module
Run
$python demo.py -v
2 items had no tests:
__main__
__main__.say_hi
0 tests in 2 items.
0 passed.
Test passed.
Run with PyDoc
$pydoc -p 1234