Correct warnings with unicode message.

This commit is contained in:
wanghui 2017-05-25 17:59:42 +08:00
parent 17f64704c2
commit c39689da41
No known key found for this signature in database
GPG Key ID: 9DD1E28DBFC06C26
2 changed files with 32 additions and 1 deletions

View File

@ -5,6 +5,8 @@ from contextlib import contextmanager
import pytest
from _pytest import compat
def _setoption(wmod, arg):
"""
@ -62,7 +64,7 @@ def catch_warnings_for_item(item):
for warning in log:
msg = warnings.formatwarning(
warning.message, warning.category,
compat.safe_str(warning.message), warning.category,
warning.filename, warning.lineno, warning.line)
item.warn("unused", msg)

View File

@ -1,3 +1,6 @@
# -*- coding: utf8 -*-
from __future__ import unicode_literals
import pytest
@ -106,3 +109,29 @@ def test_ignore(testdir, pyfile_with_warnings, method):
])
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
def test_unicode(testdir, pyfile_with_warnings):
testdir.makepyfile('''
# -*- coding: utf8 -*-
import warnings
import pytest
@pytest.fixture
def fix():
warnings.warn(u"测试")
yield
def test_func(fix):
pass
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*== %s ==*' % WARNINGS_SUMMARY_HEADER,
'*test_unicode.py:8: UserWarning: \u6d4b\u8bd5',
'*warnings.warn(u"\u6d4b\u8bd5")',
'* 1 passed, 1 warnings*',
])