Skip to content

Commit

Permalink
Fix warning about non-ascii warnings even when they are ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Oct 2, 2017
1 parent 966391c commit 94ae943
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _pytest/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def catch_warnings_for_item(item):

if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
new_args = [compat.safe_str(m) for m in warn_msg.args]
unicode_warning = warn_msg.args != new_args
unicode_warning = list(warn_msg.args) != new_args
warn_msg.args = new_args

msg = warnings.formatwarning(
Expand Down
1 change: 1 addition & 0 deletions changelog/2809.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pytest no longer complains about warnings with unicode messages being non-ascii compatible even for ascii-compatible messages.
20 changes: 20 additions & 0 deletions testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ def test_func(fix):
])


def test_py2_unicode_ascii(testdir):
"""Ensure that our warning about 'unicode warnings containing non-ascii messages'
does not trigger with ascii-convertible messages"""
testdir.makeini('[pytest]')
testdir.makepyfile('''
import pytest
import warnings
@pytest.mark.filterwarnings('always')
def test_func():
warnings.warn(u"hello")
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*== %s ==*' % WARNINGS_SUMMARY_HEADER,
'*warnings.warn(u"hello")',
'* 1 passed, 1 warnings in*'
])


def test_works_with_filterwarnings(testdir):
"""Ensure our warnings capture does not mess with pre-installed filters (#2430)."""
testdir.makepyfile('''
Expand Down

0 comments on commit 94ae943

Please sign in to comment.