Skip to content

Commit

Permalink
Call repr() when pretty() fails in _pprint_displayhook
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shimon committed Aug 5, 2020
1 parent 4035263 commit d41e6dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions news/print-mocks-correctly.rst
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Viewing mock objects in the shell

**Security:**

* <news item>
4 changes: 3 additions & 1 deletion xonsh/main.py
Expand Up @@ -251,9 +251,11 @@ def _pprint_displayhook(value):
builtins._ = value
return
env = builtins.__xonsh__.env
printed_val = None
if env.get("PRETTY_PRINT_RESULTS"):
printed_val = pretty(value)
else:
if not isinstance(printed_val, str):
# pretty may fail (i.e for unittest.mock.Mock)
printed_val = repr(value)
if HAS_PYGMENTS and env.get("COLOR_RESULTS"):
tokens = list(pygments.lex(printed_val, lexer=pyghooks.XonshLexer()))
Expand Down

0 comments on commit d41e6dd

Please sign in to comment.