Skip object serialization in equality checks if possible.

Remove unnecessary serialization from __eq__, __ne__.
Test that serialization only happens in equality checks when necessary.
Add mock to dev-requirements.