Escape % character in the assertion message. closes #604
--HG-- branch : test_for_issue_604
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user