From 34b4e216066cef4f301f1069981fae1cd39ceeee Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 4 Jul 2019 09:34:55 -0300 Subject: [PATCH] Include two more cases for non-ascii encoded bytes --- src/_pytest/_code/code.py | 2 +- testing/python/raises.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 4e0c45a37..175d6fda0 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -577,7 +577,7 @@ class ExceptionInfo(object): ) if not re.search(regexp, value): raise AssertionError( - u"Pattern '{}' not found in '{}'".format(regexp, value) + u"Pattern {!r} not found in {!r}".format(regexp, value) ) return True diff --git a/testing/python/raises.py b/testing/python/raises.py index 70f4af306..9cd3ec717 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -221,7 +221,7 @@ class TestRaises(object): int("asdf") msg = "with base 16" - expr = r"Pattern '{}' not found in 'invalid literal for int\(\) with base 10: 'asdf''".format( + expr = r"Pattern '{}' not found in \"invalid literal for int\(\) with base 10: 'asdf'\"".format( msg ) with pytest.raises(AssertionError, match=expr): @@ -305,6 +305,18 @@ class TestUnicodeHandling: pytest.param( u"hello", b"world", pytest.raises(AssertionError), marks=py2_only ), + pytest.param( + u"😊".encode("UTF-8"), + b"world", + pytest.raises(AssertionError), + marks=py2_only, + ), + pytest.param( + u"world", + u"😊".encode("UTF-8"), + pytest.raises(AssertionError), + marks=py2_only, + ), ], ) def test_handling(self, message, match, expectation):