python3: doctest helper/internal functions?
Question: 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() 
    


Answer: 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 __name__ == "__main__":
        import doctest
        __test__ = {'helper': B()}
        doctest.testmod() 
    

`doctest.testmod()` looks for the `__test__` global dictionary and looks for
docstrings on any classes, methods, functions and modules in the values; any
string values are directly executed as docstring tests.

If `B()` does _other_ things besides, then you probably should make `helper()`
a simple global function instead:

    
    
    def B():
        # uses helper
    
    def helper()
        """
        >>> some doctest
        result
        """
    
    # ...
    
    if __name__ == "__main__":
        import doctest
        doctest.testmod() 
    

