Escape % character in the assertion message. closes #604
This commit is contained in:
parent
ba8ae427e2
commit
a759da0208
|
@ -5,6 +5,9 @@ Unreleased
|
||||||
|
|
||||||
- removed outdated japanese docs from source tree.
|
- removed outdated japanese docs from source tree.
|
||||||
|
|
||||||
|
- Escape % character in the assertion message.
|
||||||
|
|
||||||
|
|
||||||
2.6.3
|
2.6.3
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,7 @@ def _format_assertmsg(obj):
|
||||||
t = py.builtin.text
|
t = py.builtin.text
|
||||||
else:
|
else:
|
||||||
t = py.builtin.bytes
|
t = py.builtin.bytes
|
||||||
s = s.replace(t("\n"), t("\n~"))
|
s = s.replace(t("\n"), t("\n~")).replace(t("%"), t("%%"))
|
||||||
if is_repr:
|
if is_repr:
|
||||||
s = s.replace(t("\\n"), t("\n~"))
|
s = s.replace(t("\\n"), t("\n~"))
|
||||||
return s
|
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*",
|
"*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 test_boolop(self):
|
||||||
def f():
|
def f():
|
||||||
f = g = False
|
f = g = False
|
||||||
|
|
Loading…
Reference in New Issue