[Python-Dev] doctest, exec and module (original) (raw)

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