This is the example project for Python Testing 101: doctest, part of the Python Testing 101 series from Automation Panda. It will work for Python 2 and 3.
This project has two modules:
com.automationpanda.example.calc_funccontains math functions. Doctests are embedded in function docstrings.com.automationpanda.example.calc_classcontains a basic Calculator class. Doctests appear in a separate text file atdoctests/test_calc_class.txt.
For com.automationpanda.example.calc_func:
python -m doctest com/automationpanda/example/calc_func.pyto run the tests.python com/automationpanda/example/calc_func.pyto run the tests and generate XML reports.
For com.automationpanda.example.calc_class:
python -m doctest doctests/test_calc_class.txtto run the tests in the separate text file.
Warning: By default, doctests will not print anything if tests are successful.
Add the -v option to print verbose output.