[TIP] Unittesting command line scripts with unittest2?

Michael Foord fuzzyman at voidspace.org.uk
Thu Jul 29 05:42:45 PDT 2010


On 29/07/2010 05:35, Jorge Vargas wrote:
> 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.
>    
It looks okay. You probably mean tearDown rather than teadDown.

Michael

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the testing-in-python mailing list