[TIP] testing __init__
alfredodeza at gmail.com
Sat Apr 10 06:42:46 PDT 2010
On Fri, Apr 9, 2010 at 9:06 PM, David Stanek <dstanek at dstanek.com> wrote:
> On Fri, Apr 9, 2010 at 8:54 PM, Alfredo Deza <alfredodeza at gmail.com>
> > Hi
> > I am having issues testing the constructor of a class that has a
> > block.
> > Should __init__ raise an exception so I can catch via self.assertRaises
> > 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__?
> Do you have a code snippet?
> If I understand you correctly I'd write at least two tests. Something like:
> def test_an_error_is_thrown():
> # setup some mock stuff to make the __init__ raise an exception
> ClassUnderTest(some mocks or something)
> I overlooked the possibility of using mock, thanks for pointing that out.
> def test_good_behavior():
> # setup some mock stuff in a good way
> x = ClassUnderTest(some mocks or something)
> # assert some behavior
> blog: http://www.traceback.org
> twitter: http://twitter.com/dstanek
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python