unit testing

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Oct 5 22:09:42 EDT 2007


Ben Finney <bignose+hates-spam at benfinney.id.au> writes:

> Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> 
> > Giampaolo Rodolà <gnewsg at gmail.com> writes:
> > > What's the equivalent of unittest's "assertRaises"?
> > 
> > def test_raises():
> >     try:
> >        thingy()
> >        assert 42 == 43
> 
> Clearer would be:
> 
>         assert False

Or even better:

    def test_raises_good_exception():
        try:
            thingy()
        except GoodException:
            pass
        else:
            raise AssertionError("Did not raise expected GoodException")

-- 
 \         "Dad always thought laughter was the best medicine, which I |
  `\        guess is why several of us died of tuberculosis."  -- Jack |
_o__)                                                           Handey |
Ben Finney



More information about the Python-list mailing list