blob: 6787c2a3dc03c4a029d6225dd9712723d24822cd [file] [log] [blame]
Patrick Williams73bd93f2024-02-20 08:07:48 -06001From 8480bb6d0500f933be039cfec65e04157e6ecffe Mon Sep 17 00:00:00 2001
2From: Bruno Oliveira <nicoddemus@gmail.com>
3Date: Tue, 19 Dec 2023 08:24:23 -0300
4Subject: [PATCH 1/3] Fix tests for Python 3.11 and 3.12
5
6Fixes #401.
7Upstream-Status: Backport [https://github.com/pytest-dev/pytest-mock/pull/403]
8Signed-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
13diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py
14index 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
29From c596504e062be06475b03122c9c0cc732ae87840 Mon Sep 17 00:00:00 2001
30From: "pre-commit-ci[bot]"
31 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
32Date: Tue, 19 Dec 2023 11:24:38 +0000
33Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks
34
35for more information, see https://pre-commit.ci
36---
37 tests/test_pytest_mock.py | 4 +++-
38 1 file changed, 3 insertions(+), 1 deletion(-)
39
40diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py
41index 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
56From 6da5b0506d6378a8dbe5ae314d5134e6868aeabd Mon Sep 17 00:00:00 2001
57From: danigm <daniel.garcia@suse.com>
58Date: Wed, 20 Dec 2023 16:02:13 +0100
59Subject: [PATCH 3/3] Update expected message to match python 3.11.7 (#404)
60
61https://github.com/python/cpython/issues/111019
62
63Fixes #401.
64Closes #403.
65---
66 tests/test_pytest_mock.py | 6 +++++-
67 1 file changed, 5 insertions(+), 1 deletion(-)
68
69diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py
70index 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"