Community: Framework mailing list archives

expert-framework@mail.odoo.com

Re: assert_equals in yaml python blocks

by
Camptocamp France SAS, Alexandre Fayolle - Camptocamp
- 09/23/2014 08:13:35
On 23/09/2014 13:06, Leonardo Pistone wrote:
> Hi all,
>
> In yaml tests we need to make assertions, and often these go in python
> blocks and not yaml !assert blocks. The reason is that those are very
> brittle (see for example https://github.com/odoo/odoo/issues/2223) so
> I don't see improving them as a good idea.
>
> Instead, python blocks work fine, but we could improve how assertions work.
>
> For example, saying
>
> assert object.actual_value == 'expected_string'
>
> Works but gives no meaningful error if it fails. To have that we would
> need all that:
>
> actual = object.actual_value
> expected = 'expected_string'
> assert actual == expected, "Assertion Error: {0} !=
> {1}".format(actual, expected)
>
> repeated for every assertion. Standard Python unittests provide
> methods like AssertEquals that do just that, but they are only
> available in TestCase subclasses.
>
> The nose package provides among other things the possibility to use
> the proper assertions outside TestCase. In a python yaml block, we
> could then do just:
>
> from nose.tools import *
> assert_equals(object.expected, expected_string)
>
> and get good failures.
>
> For myself, I don't see any ill effects in adding a python dependency
> on a community module. We just declare it on __openerp__.py and
> .travis.yml.
>
> What do you think? Thanks!ww.odoo.com/groups?unsubscribe
>                     

No objection on my side. And I agree that using nose's implementation is
the most convenient way of getting helpful errors (1 overhead line to
import, and then you run, compared to the hasle of using the methods in
unittest's TestCase)

-- 
Alexandre Fayolle
Chef de Projet
Tel : + 33 (0)4 79 26 57 94

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac Cedex
http://www.camptocamp.com