Merged in bubenkoff/pytest/test_for_issue_604 (pull request #220)

Escape % character in the assertion message
This commit is contained in:
holger krekel 2014-10-07 09:06:47 +02:00
commit b6475b058f
3 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,8 @@ Unreleased
at the beginning of strings and even that is deprecated. Use "not" instead.
This should allow to pick parametrized tests where "-" appeared in the parameter.
- fix issue604: Escape % character in the assertion message.
2.6.3
-----------

View File

@ -373,7 +373,7 @@ def _format_assertmsg(obj):
t = py.builtin.text
else:
t = py.builtin.bytes
s = s.replace(t("\n"), t("\n~"))
s = s.replace(t("\n"), t("\n~")).replace(t("%"), t("%%"))
if is_repr:
s = s.replace(t("\\n"), t("\n~"))
return s

View File

@ -172,6 +172,18 @@ class TestAssertionRewrite:
"*assert 1 == 2*",
])
def test_assertion_message_escape(self, testdir):
testdir.makepyfile("""
def test_foo():
assert 1 == 2, 'To be escaped: %'
""")
result = testdir.runpytest()
assert result.ret == 1
result.stdout.fnmatch_lines([
"*AssertionError: To be escaped: %",
"*assert 1 == 2",
])
def test_boolop(self):
def f():
f = g = False