python3: doctest helper/internal functions?
问题 How do I make the following work so that helpers's test is run? It doesen't. def B(): def helper(): """ >>> some doctest result """ ... if __name__ == "__main__": import doctest doctest.testmod() 回答1: Nested functions cannot be found, because the function object doesn't exist until the B() function is run. You'd have to return it as the result of calling the B() function, then assign it to the __test__ dictionary: def B() def helper() """ >>> some doctest result """ return helper # ... if _