2

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?

2
  • does Document implement __str__ and/or __repr__? If not, or if you don't like how they are implemented you could patch them. Commented Apr 12, 2023 at 17:48
  • 1
    I was thinking same as Jon. You can probably do something like monkeypatch.setattr(Document, "__repr__", Document.to_json). Commented Apr 12, 2023 at 17:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.