diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-10-09 13:34:03 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-10-09 15:08:22 +0200 |
| commit | a8f888feb464afd7cfbe024242fa2a405a2d5f90 (patch) | |
| tree | c68ca9a89a1e229ee4ba44bc881fab46ac2abddf | |
| parent | 9a2bceed1aab52f65820c378f5ae1f608322b55c (diff) | |
Improved assertion error messages in validators tests
| -rw-r--r-- | tests/modeltests/validators/tests.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py index 018be6ae59..32bbf62c94 100644 --- a/tests/modeltests/validators/tests.py +++ b/tests/modeltests/validators/tests.py @@ -162,11 +162,23 @@ def create_simple_test_method(validator, expected, value, num): if expected is not None and issubclass(expected, Exception): test_mask = 'test_%s_raises_error_%d' def test_func(self): - self.assertRaises(expected, validator, value) + # assertRaises not used, so as to be able to produce an error message + # containing the tested value + try: + validator(value) + except expected: + pass + else: + self.fail("%s not raised when validating '%s'" % ( + expected.__name__, value)) else: test_mask = 'test_%s_%d' def test_func(self): - self.assertEqual(expected, validator(value)) + try: + self.assertEqual(expected, validator(value)) + except ValidationError as e: + self.fail("Validation of '%s' failed. Error message was: %s" % ( + value, str(e))) if isinstance(validator, types.FunctionType): val_name = validator.__name__ else: |
