From 79c2a479851c7e368f3263ef60a64a1ffea917e7 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 23 Aug 2014 12:10:16 +0200 Subject: [PATCH] Improve the docstring further --- _pytest/assertion/rewrite.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 6cb5ee96c..cb8acc187 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -327,12 +327,15 @@ def rewrite_asserts(mod): def _saferepr(obj): - """Get a safe repr of an object for assertion error messages + """Get a safe repr of an object for assertion error messages. The assertion formatting (util.format_explanation()) requires newlines to be escaped since they are a special character for it. - But py.io.saferepr allows newlines, so we need to escape them - here. + Normally assertion.util.format_explanation() does this but for a + custom repr it is possible to contain one of the special escape + sequences, especially '\n{' and '\n}' are likely to be present in + JSON reprs. + """ repr = py.io.saferepr(obj) if py.builtin._istext(repr):