← Back to team overview

openerp-community team mailing list archive

Re: Asserting exceptions in yaml tests

 

Le 11/09/2011 17:54, Christophe Combelles a écrit :
Le 01/09/2011 17:05, Olivier Dony a écrit :
On 08/28/2011 02:19 PM, Georges Racinet wrote:
After a quick search on launchpad, and a code read, I couldn't find much
on the matter of cleanly make assertions about exceptions in Yaml tests.

To say it quickly, I'm thinking of an analog of unittest's assertRaises
(http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises)

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.

I get odd behaviours after a try: except: block in a !python directive in YAML.
I think this kind of test is not even possible, and I suspect the test
transaction is rolled-back anyway during the exception so that subsequent tests
cannot be done :(

This is it.
The only way I could do it inside the test is by monkeypatching the cursor to inhibit the rollback method. Something like that :
(the "create" method is supposed to fail, that's the purpose of the test) :

- !python {model: sale.order.line}: |
    try:
        # monkeypatch the cursor to avoid rollback!
        rollback = cr.rollback
        cr.rollback = lambda x: None

        model.create(cr, uid, {
          'order_id': ref('my_order_001'),
          'name': 'ORD001LIN001',
          'delay': 10.0,
          'price_unit': 27.0,
          'type': 'make_to_order',
          'product_uom_qty': 2,
          'product_uom': ref('product.product_uom_unit'),
          'state': 'draft',
          'product_id': ref('my_product_1'),
        }, context)
    except:
        # restore the cursor rollback method
        cr.rollback = rollback
    else:
        raise Exception('Test should fail')





Christophe




In any case, if that's something really missing in the yaml testing
framework, I'd be glad to blueprint and implement it (although a
backport to 6.0 branch would be our primary interest)

That would certainly be a welcome contribution! The chance of seeing it
merged in 6.0 are low however, as the stable branches policy restricts
allowed patches to bugfixes only.
That said, it could be merged in trunk and thus part of the upcoming
6.1, and nothing prevents you to run your own yaml-patched 6.0 server
for your 6.0 developments, until you decide to move on to 6.1. You'd
still have the guarantee that those tests would be ready for 6.1.

As for shaping up such a blueprint, may I suggest the mailing-list of
the framework experts team
(https://launchpad.net/~openerp-expert-framework) as an appropriate
place to discuss it?

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to : openerp-community@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~openerp-community
More help : https://help.launchpad.net/ListHelp



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to : openerp-community@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~openerp-community
More help : https://help.launchpad.net/ListHelp

--
Christophe Combelles

mob +33 (0)6 08 955 845
Anybox SAS http://www.anybox.fr
Blog http://ccomb.gorfou.fr
Partenaire OpenERP http://is.gd/openerp
Partenaire Google APPS http://is.gd/googleapps



References