[TIP] Unittesting command line scripts with unittest2?

Jorge Vargas jorge.vargas at gmail.com
Wed Jul 28 21:35:21 PDT 2010


On Thu, Jul 29, 2010 at 12:09 AM, Jorge Vargas <jorge.vargas at gmail.com> wrote:
> On Wed, Jul 28, 2010 at 6:31 PM, holger krekel <holger at merlinux.eu> wrote:
>> On Wed, Jul 28, 2010 at 18:10 -0400, Jorge Vargas wrote:
>>
> Right now I'm having troubles with the stdout replacement, as it's
> swallowing up the coverage report :)
>
> Seems like tearDown is called after the coverage report, because I get
> the dots and the ok/failure message.
>
I believe the following code should do it right.

http://paste.ofcode.org/bVdw7bcu74VhaAtaAk33KM

it
a- stores a copy of stdout/stderr, so you can assert against it after
calling made and it echos back to the terminal
b- it restores the original values just in case something else needs them.

And I haven't added Holger's suggesting of doing main(args=None) which
I think it's a good idea.



More information about the testing-in-python mailing list