[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] doctest, exec and __module__
From:       Martijn Faassen <faassen () startifact ! com>
Date:       2008-06-25 20:26:27
Message-ID: g3u9lj$5me$1 () ger ! gmane ! org
[Download RAW message or body]

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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic