|
4 | 4 | import six
|
5 | 5 |
|
6 | 6 | import pytest
|
| 7 | +from _pytest.compat import dummy_context_manager |
7 | 8 | from _pytest.outcomes import Failed
|
8 | 9 | from _pytest.warning_types import PytestDeprecationWarning
|
9 | 10 |
|
@@ -279,8 +280,34 @@ def __class__(self):
|
279 | 280 | pass
|
280 | 281 | assert "via __class__" in excinfo.value.args[0]
|
281 | 282 |
|
282 |
| - def test_unicode_message(self): |
283 |
| - """pytest.raises should be able to match unicode messages when using a unicode regex (#5478) |
284 |
| - """ |
285 |
| - with pytest.raises(AssertionError, match=u"\u2603"): |
286 |
| - assert False, u"\u2603" |
| 283 | + |
| 284 | +class TestUnicodeHandling: |
| 285 | + """Test various combinations of bytes and unicode with pytest.raises (#5478) |
| 286 | +
|
| 287 | + https://github.com/pytest-dev/pytest/pull/5479#discussion_r298852433 |
| 288 | + """ |
| 289 | + |
| 290 | + success = dummy_context_manager |
| 291 | + py2_only = pytest.mark.skipif( |
| 292 | + six.PY3, reason="bytes in raises only supported in Python 2" |
| 293 | + ) |
| 294 | + |
| 295 | + @pytest.mark.parametrize( |
| 296 | + "message, match, expectation", |
| 297 | + [ |
| 298 | + (u"\u2603", u"\u2603", success()), |
| 299 | + (u"\u2603", u"\u2603foo", pytest.raises(AssertionError)), |
| 300 | + pytest.param(b"hello", b"hello", success(), marks=py2_only), |
| 301 | + pytest.param( |
| 302 | + b"hello", b"world", pytest.raises(AssertionError), marks=py2_only |
| 303 | + ), |
| 304 | + pytest.param(u"hello", b"hello", success(), marks=py2_only), |
| 305 | + pytest.param( |
| 306 | + u"hello", b"world", pytest.raises(AssertionError), marks=py2_only |
| 307 | + ), |
| 308 | + ], |
| 309 | + ) |
| 310 | + def test_handling(self, message, match, expectation): |
| 311 | + with expectation: |
| 312 | + with pytest.raises(RuntimeError, match=match): |
| 313 | + raise RuntimeError(message) |
0 commit comments