doctest
tests within typechecked functions.This doesn't work out of the box since the doctest module looks for tests by recursing through a set of objects and looking for docstrings. If it finds a function, it checks that the functions
func_globals
object is the same object as the function's module's __dict__
property. This is not true of any decorated function where the decorator is defined outside the module the function is defined in.Anyway, the new
typecheck.doctest
module allows you to bypass the check that doctest usually uses and replaces it with a much more liberal one that just verifies that a function's __module__
property is the same as the name of the module in which the function is defined.