Add test when using native strings with non-ascii chars
This commit is contained in:
parent
24d3e01548
commit
5d4703852e
|
@ -435,7 +435,10 @@ class OutcomeException(Exception):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.msg:
|
if self.msg:
|
||||||
return py._builtin._totext(self.msg)
|
val = self.msg
|
||||||
|
if isinstance(val, bytes):
|
||||||
|
val = py._builtin._totext(val, errors='replace')
|
||||||
|
return val
|
||||||
return "<%s instance>" %(self.__class__.__name__,)
|
return "<%s instance>" %(self.__class__.__name__,)
|
||||||
__str__ = __repr__
|
__str__ = __repr__
|
||||||
|
|
||||||
|
|
|
@ -440,16 +440,19 @@ def test_pytest_fail_notrace(testdir):
|
||||||
assert 'def teardown_function' not in result.stdout.str()
|
assert 'def teardown_function' not in result.stdout.str()
|
||||||
|
|
||||||
|
|
||||||
def test_pytest_fail_notrace_unicode(testdir):
|
@pytest.mark.parametrize('str_prefix', ['u', ''])
|
||||||
|
def test_pytest_fail_notrace_non_ascii(testdir, str_prefix):
|
||||||
"""Fix pytest.fail with pytrace=False with non-ascii characters (#1178).
|
"""Fix pytest.fail with pytrace=False with non-ascii characters (#1178).
|
||||||
|
|
||||||
|
This tests with native and unicode strings containing non-ascii chars.
|
||||||
"""
|
"""
|
||||||
testdir.makepyfile(u"""
|
testdir.makepyfile(u"""
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
def test_hello():
|
def test_hello():
|
||||||
pytest.fail(u'oh oh: ☺', pytrace=False)
|
pytest.fail(%s'oh oh: ☺', pytrace=False)
|
||||||
""")
|
""" % str_prefix)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
result.stdout.fnmatch_lines(['*test_hello*', "oh oh: ☺"])
|
result.stdout.fnmatch_lines(['*test_hello*', "oh oh: ☺"])
|
||||||
|
|
Loading…
Reference in New Issue