diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 46eaac08b57..d3465db82d9 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -109,12 +109,17 @@ def __repr__(self): assert s1 == s2 malformed_utf8 = b"\x80" - with pytest.raises(UnicodeDecodeError) as excinfo: - assert m.str_from_object(malformed_utf8) - assert 'invalid start byte' in str(excinfo.value) - with pytest.raises(UnicodeDecodeError) as excinfo: - assert m.str_from_handle(malformed_utf8) - assert 'invalid start byte' in str(excinfo.value) + if sys.version_info.major < 3: + with pytest.raises(UnicodeDecodeError) as excinfo: + assert m.str_from_object(malformed_utf8) + assert 'invalid start byte' in str(excinfo.value) + with pytest.raises(UnicodeDecodeError) as excinfo: + assert m.str_from_handle(malformed_utf8) + assert 'invalid start byte' in str(excinfo.value) + else: + assert m.str_from_object(malformed_utf8) == "b'\\x80'" + assert m.str_from_handle(malformed_utf8) == "b'\\x80'" + def test_bytes(doc):