[TIP] testing __init__

Michael Foord fuzzyman at voidspace.org.uk
Sat Apr 10 06:47:32 PDT 2010


On 10/04/2010 01:54, Alfredo Deza wrote:
> Hi
>
> I am having issues testing the constructor of a class that has a 
> try/except block.
>
> Should __init__ raise an exception so I can catch via 
> self.assertRaises to make it easier to test? Or are there other ways
> to make __init__ "testable"?
>
> What is the way you guys use the most (or like the best) for testing 
> __init__?

Well, avoiding doing things like that in constructors is one way to make 
them more testable. Another way is to factor that code into a separate 
method so that it can be stubbed out (test your constructor calls it) 
and also tested separately.

Michael

>
>
>
> Thanks!
>
>
>
> -- 
> Alfredo Deza
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>    


-- 
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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20100410/7bfbd2e1/attachment.htm>


More information about the testing-in-python mailing list