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