[Python-Dev] doctest, exec and __module__
Martijn Faassen
faassen at startifact.com
Wed Jun 25 22:26:27 CEST 2008
Fred Drake wrote:
> On Jun 25, 2008, at 2:45 PM, Martijn Faassen wrote:
>> This places new key/value pairs into a dictionary, in this case
>> test.globs. Unfortunately when the execution results in a class
>> definition, it'll have its __module__ attribute set to '__builtin__'.
>> Try as I might, I couldn't convince exec to do it any differently.
>
> The zope.testing package has a way to work around this from
> setup/teardown functions passed to the DocFileSuite (or whatever wrapper
> you're using). See the module zope.testing.module for the functions.
Thanks, I should've checked that!
> Essentially, the __name__ needs to be set in test.globs; class
> construction uses the global value for __name__ to provide __module__;
> doctests normally don't have one, so it acquires the value from
> __builtin__.__name__ instead. Which is, of course, horribly wrong.
Okay, so is this mystery mechanism that I was missing. Sorry to bother
people here on the list.
Regards,
Martijn
More information about the Python-Dev
mailing list