summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-04 12:28:38 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-04 13:33:37 +0000
commit2be2f64aeb33e29821d53baa0b540dc9474b9cdd (patch)
tree11f66fb30e63a001115e802ff8e5d7f6a863e0d5
parent3b1d00acda935810826e476ad49a48bf5947c0ab (diff)
[FIX] tests: properly log errors
If a test is failing with assertRecordValues, the comparison and the error logging were not computed the same way. The _compare_candidate was accessing the record via record[field_name] which uses the cache While the _format_message was doing records.read(...) which queries directly the database. If the test was failing (correctly) because of a wrong cache invalidation (e.g. update the value directly in SQL without invalidating the cache), the error message would look like: AssertionError: Record doesn't match expected values at index 0. Current values: {'id': 42, 'name': 'Foo'} Expected values: {'name': 'Foo'} closes odoo/odoo#34589 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
-rw-r--r--odoo/tests/common.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/odoo/tests/common.py b/odoo/tests/common.py
index d2aff0013cb..adb33d79616 100644
--- a/odoo/tests/common.py
+++ b/odoo/tests/common.py
@@ -334,9 +334,23 @@ class BaseCase(TreeCase, MetaCase('DummyCase', (object,), {})):
return False
return True
+ def _repr_field_value(record, field_name):
+ record_value = record[field_name]
+ field_type = record._fields[field_name].type
+ if field_type == 'monetary':
+ currency_field_name = record._fields[field_name].currency_field
+ record_currency = record[currency_field_name]
+ return record_currency and record_currency.round(record_value) or record_value
+ elif field_type in ('one2many', 'many2many'):
+ return set(record_value.ids)
+ elif field_type == 'many2one':
+ return record_value.id
+ else:
+ return record_value
+
def _format_message(records, expected_values):
''' Return a formatted representation of records/expected_values. '''
- all_records_values = records.read(list(expected_values[0].keys()), load=False)
+ all_records_values = [{key: _repr_field_value(record, key) for key in expected_values[0]} for record in records]
msg1 = '\n'.join(pprint.pformat(dic) for dic in all_records_values)
msg2 = '\n'.join(pprint.pformat(dic) for dic in expected_values)
return 'Current values:\n\n%s\n\nExpected values:\n\n%s' % (msg1, msg2)