python function in pipe

attn.steven.kuo at gmail.com attn.steven.kuo at gmail.com
Sat Apr 28 12:58:59 EDT 2007


On Apr 28, 6:37 am, Bart <u... at o2.pl> wrote:
> Hi everyone!
>
> Im using module that gives errors to stderr/stdout  (generated by SWIG)
> Problem is that I need to parse this errors/information from module.
>
> os.popen3 looks nice but this executes  command  not  function.
>
> Is there any solution?
>


Perhaps you're looking for the unittest module?

You can use assertRaises if an exception is raised
by the function.

You can also redirect sys.stderr and sys.stdout as needed
and test the captured strings with assertEquals.



Else you can wrap the module under test in another
module:

# mytest.py

import module_under_test

if __name__ == "__main__":
    module_under_test.foo()

Then, using os.popen3 (or subprocess),
run "python mytest.py" as your command.

--
Hope this helps,
Steven




More information about the Python-list mailing list