Skip to content

Commit

Permalink
Merge pull request #2466 from nicoddemus/remove-unicode-warning
Browse files Browse the repository at this point in the history
Remove UnicodeWarning from pytest warnings
  • Loading branch information
RonnyPfannschmidt committed Jun 7, 2017
2 parents 57e2ced + 9d41eae commit d2db662
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions _pytest/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions changelog/2463.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``UnicodeWarning`` is issued from the internal pytest warnings plugin only when the message contains non-ascii
unicode (Python 2 only).
2 changes: 1 addition & 1 deletion testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_func(fix):

'*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*',
])

Expand Down

0 comments on commit d2db662

Please sign in to comment.