From 0d33b87579c295db8c1b6c95fc5df61e964e569a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 27 Jan 2020 14:10:58 +0100 Subject: [PATCH] [FIX] finally make pytest work properly w/ model proxy At some point pytest added support for dataclass & attrs introspection by looking up some specific meta-fields when trying to format objects (after an assertion fails). It tries to access the attributes, falls back to something else if it gets an AttributeError but apparently falls over if it gets something else, which is what'd happen here as read() would generate a ValueError which would get re-raised as-is on the client side.. However pytest doesn't really make the issue clear, and the logging from RPC likely got lost in the noise from the github logging. The fix is to simply convert errors from read() into proper AttributeError. And blacklist fields we know make no sense to avoid confusing tracebacks in the log. --- conftest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 7b71a9a8..7da5b5b2 100644 --- a/conftest.py +++ b/conftest.py @@ -996,6 +996,8 @@ class Model: return Model(self._env, self._model, ids, fields=self._fields) def __getattr__(self, fieldname): + if fieldname in ['__dataclass_fields__', '__attrs_attrs__']: + raise AttributeError('%r is invalid on %s' % (fieldname, self._model)) if not self._ids: return False @@ -1003,7 +1005,10 @@ class Model: if fieldname == 'id': return self._ids[0] - val = self.read([fieldname])[0][fieldname] + try: + val = self.read([fieldname])[0][fieldname] + except Exception: + raise AttributeError('%r is invalid on %s' % (fieldname, self._model)) field_description = self._fields[fieldname] if field_description['type'] in ('many2one', 'one2many', 'many2many'): val = val or []