Escape % character in the assertion message. closes #604
--HG-- branch : test_for_issue_604
This commit is contained in:
parent
24468a6f34
commit
e1aed27c15
|
@ -5,6 +5,9 @@ Unreleased
|
|||
|
||||
- removed outdated japanese docs from source tree.
|
||||
|
||||
- Escape % character in the assertion message.
|
||||
|
||||
|
||||
2.6.3
|
||||
-----------
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
def test_assert_message_fail():
|
||||
'''
|
||||
Check if custom message with % sign do not raise ValueError
|
||||
Later test can be parametrized with other problematic chars
|
||||
'''
|
||||
|
||||
MESSAGE = 'Message with %'
|
||||
|
||||
try:
|
||||
assert False, MESSAGE
|
||||
except ValueError, ve:
|
||||
assert False, 'ValueError was raised with the following message: ' \
|
||||
+ ve.message
|
||||
except AssertionError, ae:
|
||||
assert MESSAGE == ae.message, 'Assertion message: ' + ae.message \
|
||||
+ ' is different than expected: ' + MESSAGE
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue