Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 1 | From 8480bb6d0500f933be039cfec65e04157e6ecffe Mon Sep 17 00:00:00 2001 |
| 2 | From: Bruno Oliveira <nicoddemus@gmail.com> |
| 3 | Date: Tue, 19 Dec 2023 08:24:23 -0300 |
| 4 | Subject: [PATCH 1/3] Fix tests for Python 3.11 and 3.12 |
| 5 | |
| 6 | Fixes #401. |
| 7 | Upstream-Status: Backport [https://github.com/pytest-dev/pytest-mock/pull/403] |
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 9 | --- |
| 10 | tests/test_pytest_mock.py | 3 +-- |
| 11 | 1 file changed, 1 insertion(+), 2 deletions(-) |
| 12 | |
| 13 | diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py |
| 14 | index 3ee00da..7acb361 100644 |
| 15 | --- a/tests/test_pytest_mock.py |
| 16 | +++ b/tests/test_pytest_mock.py |
| 17 | @@ -246,9 +246,8 @@ def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None: |
| 18 | msg = "Expected call: {0}()\nNot called" |
| 19 | expected_message = msg.format(expected_name) |
| 20 | stub = mocker.stub(**kwargs) |
| 21 | - with pytest.raises(AssertionError) as exc_info: |
| 22 | + with pytest.raises(AssertionError, match=re.escape(expected_message)) as exc_info: |
| 23 | stub.assert_called_with() |
| 24 | - assert str(exc_info.value) == expected_message |
| 25 | |
| 26 | def test_failure_message_with_no_name(self, mocker: MagicMock) -> None: |
| 27 | self.__test_failure_message(mocker) |
| 28 | |
| 29 | From c596504e062be06475b03122c9c0cc732ae87840 Mon Sep 17 00:00:00 2001 |
| 30 | From: "pre-commit-ci[bot]" |
| 31 | <66853113+pre-commit-ci[bot]@users.noreply.github.com> |
| 32 | Date: Tue, 19 Dec 2023 11:24:38 +0000 |
| 33 | Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks |
| 34 | |
| 35 | for more information, see https://pre-commit.ci |
| 36 | --- |
| 37 | tests/test_pytest_mock.py | 4 +++- |
| 38 | 1 file changed, 3 insertions(+), 1 deletion(-) |
| 39 | |
| 40 | diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py |
| 41 | index 7acb361..c185f2a 100644 |
| 42 | --- a/tests/test_pytest_mock.py |
| 43 | +++ b/tests/test_pytest_mock.py |
| 44 | @@ -246,7 +246,9 @@ def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None: |
| 45 | msg = "Expected call: {0}()\nNot called" |
| 46 | expected_message = msg.format(expected_name) |
| 47 | stub = mocker.stub(**kwargs) |
| 48 | - with pytest.raises(AssertionError, match=re.escape(expected_message)) as exc_info: |
| 49 | + with pytest.raises( |
| 50 | + AssertionError, match=re.escape(expected_message) |
| 51 | + ) as exc_info: |
| 52 | stub.assert_called_with() |
| 53 | |
| 54 | def test_failure_message_with_no_name(self, mocker: MagicMock) -> None: |
| 55 | |
| 56 | From 6da5b0506d6378a8dbe5ae314d5134e6868aeabd Mon Sep 17 00:00:00 2001 |
| 57 | From: danigm <daniel.garcia@suse.com> |
| 58 | Date: Wed, 20 Dec 2023 16:02:13 +0100 |
| 59 | Subject: [PATCH 3/3] Update expected message to match python 3.11.7 (#404) |
| 60 | |
| 61 | https://github.com/python/cpython/issues/111019 |
| 62 | |
| 63 | Fixes #401. |
| 64 | Closes #403. |
| 65 | --- |
| 66 | tests/test_pytest_mock.py | 6 +++++- |
| 67 | 1 file changed, 5 insertions(+), 1 deletion(-) |
| 68 | |
| 69 | diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py |
| 70 | index c185f2a..01534a4 100644 |
| 71 | --- a/tests/test_pytest_mock.py |
| 72 | +++ b/tests/test_pytest_mock.py |
| 73 | @@ -25,6 +25,8 @@ |
| 74 | |
| 75 | # Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0 |
| 76 | NEW_FORMATTING = sys.version_info >= (3, 8) |
| 77 | +# Python 3.11.7 changed the output formatting, https://github.com/python/cpython/issues/111019 |
| 78 | +NEWEST_FORMATTING = sys.version_info >= (3, 11, 7) |
| 79 | |
| 80 | if sys.version_info[:2] >= (3, 8): |
| 81 | from unittest.mock import AsyncMock |
| 82 | @@ -240,7 +242,9 @@ def test_repr_with_name(self, mocker: MockerFixture) -> None: |
| 83 | |
| 84 | def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None: |
| 85 | expected_name = kwargs.get("name") or "mock" |
| 86 | - if NEW_FORMATTING: |
| 87 | + if NEWEST_FORMATTING: |
| 88 | + msg = "expected call not found.\nExpected: {0}()\n Actual: not called." |
| 89 | + elif NEW_FORMATTING: |
| 90 | msg = "expected call not found.\nExpected: {0}()\nActual: not called." |
| 91 | else: |
| 92 | msg = "Expected call: {0}()\nNot called" |