Skip to content

Commit

Permalink
pytest.fail with non-ascii characters raises an internal pytest error
Browse files Browse the repository at this point in the history
Fix #1178
  • Loading branch information
nicoddemus committed Mar 5, 2016
1 parent 3884398 commit 24d3e01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

*

* Fix (`#1178 <https://github.com/pytest-dev/pytest/issues/1178>`_):
``pytest.fail`` with non-ascii characters raises an internal pytest error.
Thanks `@nicoddemus`_ for the PR.

* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).

Expand Down
2 changes: 1 addition & 1 deletion _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def _prunetraceback(self, excinfo):
def _repr_failure_py(self, excinfo, style="long"):
if excinfo.errisinstance(pytest.fail.Exception):
if not excinfo.value.pytrace:
return str(excinfo.value)
return py._builtin._totext(excinfo.value)
return super(FunctionMixin, self)._repr_failure_py(excinfo,
style=style)

Expand Down
2 changes: 1 addition & 1 deletion _pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def __init__(self, msg=None, pytrace=True):

def __repr__(self):
if self.msg:
return str(self.msg)
return py._builtin._totext(self.msg)
return "<%s instance>" %(self.__class__.__name__,)
__str__ = __repr__

Expand Down
19 changes: 19 additions & 0 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement

import _pytest._code
Expand Down Expand Up @@ -439,6 +440,24 @@ def teardown_function(function):
assert 'def teardown_function' not in result.stdout.str()


def test_pytest_fail_notrace_unicode(testdir):
"""Fix pytest.fail with pytrace=False with non-ascii characters (#1178).
"""
testdir.makepyfile(u"""
# coding: utf-8
import pytest
def test_hello():
pytest.fail(u'oh oh: ☺', pytrace=False)
""")
result = testdir.runpytest()
if sys.version_info[0] >= 3:
result.stdout.fnmatch_lines(['*test_hello*', "oh oh: ☺"])
else:
result.stdout.fnmatch_lines(['*test_hello*', "oh oh: *"])
assert 'def test_hello' not in result.stdout.str()


def test_pytest_no_tests_collected_exit_status(testdir):
result = testdir.runpytest()
result.stdout.fnmatch_lines('*collected 0 items*')
Expand Down

0 comments on commit 24d3e01

Please sign in to comment.