Is there a way I can control the way pytest creates string representations from objects?
specifically I am using mongoengine where the objects of type Document are just lazily outputed to console as "<Document: Documment object>" and I'd like to create a more meaningful conversion to string (probably utilizing the Document.to_json() function )
can I get pytest to call a custom function whenever it needs to print out an object?
Documentimplement__str__and/or__repr__? If not, or if you don't like how they are implemented you could patch them.monkeypatch.setattr(Document, "__repr__", Document.to_json).