-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest.fail with non-ascii characters raises an internal pytest error #1439
Conversation
Does this one have a test for non Unicode non ASCII? |
I think |
At first glance it seems to test only ASCII |
Hmmm good catch! def test_pytest_fail_notrace_non_ascii_bytes(testdir):
testdir.makepyfile(u"""
# coding: utf-8
import pytest
def test_hello():
pytest.fail('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() Fails:
Not sure what the appropriate fix for this issue would be then ( |
This seems to solve it: diff --git a/_pytest/runner.py b/_pytest/runner.py
index 4f66aa9..cde94c8 100644
--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -435,7 +435,10 @@ class OutcomeException(Exception):
def __repr__(self):
if self.msg:
- return py._builtin._totext(self.msg)
+ val = self.msg
+ if isinstance(val, bytes):
+ val = py._builtin._totext(val, errors='replace')
+ return val
return "<%s instance>" %(self.__class__.__name__,)
__str__ = __repr__ What do you think @RonnyPfannschmidt? EDIT: updated diff |
I'm fine e with anything that works in the demonstrated error cases I suspect at least another upcoming overhaul |
Done |
👍 |
Support pytest.fail with non-ascii characters Fixes #1178
It seems to have been added in pytest-dev#1439 to fix pytest-dev#1178. This was only relevant for Python 2 where it was tempting to use str (== bytes) literals instead of unicode literals. In Python 3, it is unlikely that anyone passes bytes to these functions.
It seems to have been added in pytest-dev#1439 to fix pytest-dev#1178. This was only relevant for Python 2 where it was tempting to use str (== bytes) literals instead of unicode literals. In Python 3, it is unlikely that anyone passes bytes to these functions.
Fix #1178
(oops, sent the branch to
pytest
's repository by accident, sorry)