Strangeness... I was basically doing this, only I was resetting stdout
to sys.__stdout__ - and it wasn't working.

Ie, we have these three methods for setting stdout:

def paul():
    sys.stdout = sys.__stdout__

def olivier():
    reload(sys)

def chad():
    fout = open('templog', 'w')

...then olivier and chad work, but paul does not.  (...Though paul
will work AFTER olivier is run - ie, once we've reloaded sys).

To see for yourself:

http://pastebin.com/f1b77b4ae

...put that in a module, and import it... paul will fail, olivier and
chad will succeed.  (Note you can only do this once per maya session:
once reload(sys) is invoked, I have no idea how to "undo" it, without
restarting maya...)

So, apparently, maya is doing something else odd in the sys module,
other than merely redirecting sys.stdout... though, for some reason,
setting sys.stdout works as far as doctest is concerned.

Since I don't know exactly WHAT maya is doing to sys (that reload(sys)
undoes), and how important it is that it stay that way, I think I'll
go with Chad's method...

Thanks both though!  I had been considering hacking doctest somehow
with some commandPort socket connection... thank god I won't have to
do that. ;)

- Paul





On Wed, Oct 8, 2008 at 8:40 AM, Chadrik <[EMAIL PROTECTED]> wrote:
>
> or you can replace with a file pointer:
>
> import sys
> mayaout = sys.stdout
> fout = open('/var/tmp/log', 'w')
> sys.stdout = fout
> import doctest
> doctest.testmod(verbose=True)
> sys.stdout = mayaout
> fout.close()
>
>
>
>
>
> On Oct 8, 2008, at 8:36 AM, Olivier Renouard wrote:
>
>>
>> Redirecting stdout is done by setting sys.stdout.
>>
>> So in Maya this will reset stdout to it's default value :
>>
>> import sys
>> mayaout = sys.stdout
>> reload(sys)
>> import doctest
>> doctest.testmod(verbose=True)
>> sys.stdout = mayaout
>>
>> Of course the results of doctest.testmod won't be diplayed in Maya's
>> script editor then but in the standard output. On Linux for instance
>> they will display in the terminal maya was launched from though.
>>
>> Olivier
>>
>>
>> barnabas79 wrote:
>>> Hey - I was wondering if anyone has gotten doctest to work
>>> successfully from inside the script editor of a full-gui running
>>> maya.
>>>
>>> That is, doctest works fine if maya is started from within python via
>>> maya.standalone.initialize(), but if I run a doctest from the script
>>> editor, it never sees ANY output (and so all tests always fail).
>>>
>>> I'm sure this has something to do with maya's redirecting of stdout,
>>> but before I start digging into it, I was wondering if anyone here
>>> had
>>> already found a solution / workaround...
>>>>
>>>
>>>
>>
>>
>> --
>> Olivier Renouard
>>
>>
>> >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to