Skip to content

Commit 08b5836

Browse files
committed
Remove UnicodeWarning from pytest warnings
Fix #2463
1 parent f826b23 commit 08b5836

File tree

3 files changed

+1
-41
lines changed

3 files changed

+1
-41
lines changed

_pytest/warnings.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,15 @@ def catch_warnings_for_item(item):
6363

6464
for warning in log:
6565
warn_msg = warning.message
66-
unicode_warning = False
6766

6867
if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
6968
warn_msg.args = [compat.safe_str(m) for m in warn_msg.args]
70-
unicode_warning = True
7169

7270
msg = warnings.formatwarning(
7371
warn_msg, warning.category,
7472
warning.filename, warning.lineno, warning.line)
7573
item.warn("unused", msg)
7674

77-
if unicode_warning:
78-
warnings.warn(
79-
"This warning %s is broken as it's message is not a str instance"
80-
"(after all this is a stdlib problem workaround)" % msg,
81-
UnicodeWarning)
82-
8375

8476
@pytest.hookimpl(hookwrapper=True)
8577
def pytest_runtest_protocol(item):

changelog/2463.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove ``UnicodeWarning`` issued from the internal pytest warnings plugin when a captured warning contains a unicode message.

testing/test_warnings.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# -*- coding: utf8 -*-
22
from __future__ import unicode_literals
33

4-
import sys
5-
64
import pytest
75

86

@@ -112,9 +110,6 @@ def test_ignore(testdir, pyfile_with_warnings, method):
112110
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
113111

114112

115-
116-
@pytest.mark.skipif(sys.version_info < (3, 0),
117-
reason='warnings message is unicode is ok in python3')
118113
def test_unicode(testdir, pyfile_with_warnings):
119114
testdir.makepyfile('''
120115
# -*- coding: utf8 -*-
@@ -138,34 +133,6 @@ def test_func(fix):
138133
])
139134

140135

141-
@pytest.mark.skipif(sys.version_info >= (3, 0),
142-
reason='warnings message is broken as it is not str instance')
143-
def test_py2_unicode(testdir, pyfile_with_warnings):
144-
testdir.makepyfile('''
145-
# -*- coding: utf8 -*-
146-
import warnings
147-
import pytest
148-
149-
150-
@pytest.fixture
151-
def fix():
152-
warnings.warn(u"测试")
153-
yield
154-
155-
def test_func(fix):
156-
pass
157-
''')
158-
result = testdir.runpytest()
159-
result.stdout.fnmatch_lines([
160-
'*== %s ==*' % WARNINGS_SUMMARY_HEADER,
161-
162-
'*test_py2_unicode.py:8: UserWarning: \u6d4b\u8bd5',
163-
'*warnings.warn(u"\u6d4b\u8bd5")',
164-
'*warnings.py:*: UnicodeWarning: This warning*\u6d4b\u8bd5',
165-
'* 1 passed, 2 warnings*',
166-
])
167-
168-
169136
def test_works_with_filterwarnings(testdir):
170137
"""Ensure our warnings capture does not mess with pre-installed filters (#2430)."""
171138
testdir.makepyfile('''

0 commit comments

Comments
 (0)