|
25 | 25 |
|
26 | 26 | # Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0 |
27 | 27 | NEW_FORMATTING = sys.version_info >= (3, 8) |
| 28 | +# Python 3.11.7 changed the output formatting, https://github.com/python/cpython/issues/111019 |
| 29 | +NEWEST_FORMATTING = sys.version_info >= (3, 11, 7) |
28 | 30 |
|
29 | 31 | if sys.version_info[:2] >= (3, 8): |
30 | 32 | from unittest.mock import AsyncMock |
@@ -240,15 +242,18 @@ def test_repr_with_name(self, mocker: MockerFixture) -> None: |
240 | 242 |
|
241 | 243 | def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None: |
242 | 244 | expected_name = kwargs.get("name") or "mock" |
243 | | - if NEW_FORMATTING: |
| 245 | + if NEWEST_FORMATTING: |
| 246 | + msg = "expected call not found.\nExpected: {0}()\n Actual: not called." |
| 247 | + elif NEW_FORMATTING: |
244 | 248 | msg = "expected call not found.\nExpected: {0}()\nActual: not called." |
245 | 249 | else: |
246 | 250 | msg = "Expected call: {0}()\nNot called" |
247 | 251 | expected_message = msg.format(expected_name) |
248 | 252 | stub = mocker.stub(**kwargs) |
249 | | - with pytest.raises(AssertionError) as exc_info: |
| 253 | + with pytest.raises( |
| 254 | + AssertionError, match=re.escape(expected_message) |
| 255 | + ) as exc_info: |
250 | 256 | stub.assert_called_with() |
251 | | - assert str(exc_info.value) == expected_message |
252 | 257 |
|
253 | 258 | def test_failure_message_with_no_name(self, mocker: MagicMock) -> None: |
254 | 259 | self.__test_failure_message(mocker) |
|
0 commit comments