← Back to team overview

openerp-expert-framework team mailing list archive

Re: Asserting exceptions in YAML tests

 

On Monday 19 September 2011, Georges Racinet wrote:
> Here's an extract of that discussion (toplevel is Olivier) :
> > On 08/28/2011 02:19 PM, Georges Racinet wrote:
> >> > To say it quickly, I'm thinking of an analog of unittest's
> >> > assertRaises
> >> > (http://docs.python.org/library/unittest.html#unittest.TestCase.asser
> >> > tRaises)
> > 
> > You're right, there's currently no provision for assertRaises-like tests
> > in YAML, except via a custom !python block with a try/except, as you
> > noted. (...) That would certainly be a welcome contribution! (...)
> 
>...
> This gives us YAML blocks such as this one :
> 
>     !python {model: ir.model, assert_raises: lxml.etree.ParseError}: |
>         from lxml.etree import fromstring
>         fromstring('definitely not valid xml !')
> 
> What do you think of this approach ?
> I'm wondering how to unit-test that. Are there plans to unit-test
> somehow yaml imports ?

Well, so far I have been using
try:
	do_something_wrong()
        raise AssertionError("It shouldn't reach here")
except DoneWrongException:
	# yes, it failed
	pass

As you say, it is a little more bulky to write, but clearly shows the intent 
of this test..

Nevertheless, your contribution is welcome and my vote would be to merge it in 
the framework. Some developers may prefer your compact approach, why not.


-- 
Say NO to spam and viruses. Stop using Microsoft Windows!


Follow ups

References