Merge pull request #2466 from nicoddemus/remove-unicode-warning

Remove UnicodeWarning from pytest warnings
This commit is contained in:
Ronny Pfannschmidt 2017-06-07 08:00:36 +02:00 committed by GitHub
commit d2db6626cf
3 changed files with 8 additions and 5 deletions

View File

@ -66,8 +66,9 @@ def catch_warnings_for_item(item):
unicode_warning = False
if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
warn_msg.args = [compat.safe_str(m) for m in warn_msg.args]
unicode_warning = True
new_args = [compat.safe_str(m) for m in warn_msg.args]
unicode_warning = warn_msg.args != new_args
warn_msg.args = new_args
msg = warnings.formatwarning(
warn_msg, warning.category,
@ -76,8 +77,8 @@ def catch_warnings_for_item(item):
if unicode_warning:
warnings.warn(
"This warning %s is broken as it's message is not a str instance"
"(after all this is a stdlib problem workaround)" % msg,
"Warning is using unicode non convertible to ascii, "
"converting to a safe representation:\n %s" % msg,
UnicodeWarning)

2
changelog/2463.bugfix Normal file
View File

@ -0,0 +1,2 @@
``UnicodeWarning`` is issued from the internal pytest warnings plugin only when the message contains non-ascii
unicode (Python 2 only).

View File

@ -161,7 +161,7 @@ def test_py2_unicode(testdir, pyfile_with_warnings):
'*test_py2_unicode.py:8: UserWarning: \u6d4b\u8bd5',
'*warnings.warn(u"\u6d4b\u8bd5")',
'*warnings.py:*: UnicodeWarning: This warning*\u6d4b\u8bd5',
'*warnings.py:*: UnicodeWarning: Warning is using unicode non*',
'* 1 passed, 2 warnings*',
])