Technical mailing list archives

assert_equals in yaml python blocks

Leonardo Pistone
- 09/23/2014 05:09:39
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 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 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 and

What do you think? Thanks!