unit test for a printing method

Diez B. Roggisch deets at nospam.web.de
Mon Aug 28 11:58:45 EDT 2006


noro wrote:

> What is the proper way to test (using unit test) a method that print
> information?
> for example:
> 
> def A(s):
>          print '---'+s+'---'
> 
> and i want to check that A("bla") really print out "---bla---"

You can replace sys.stdout with a cStringIO-object or any other
file-protocol implementing object and such collect the data.

Diez



More information about the Python-list mailing list