Fix build with Python 3.12.1

Python 3.11.7 and 3.12.1 tweaked the format of the error message.

https://github.com/pytest-dev/pytest-mock/pull/404
This commit is contained in:
Yaakov Selkowitz 2024-01-28 16:49:37 -05:00
parent 34772b23d9
commit 150b6e22f9
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,37 @@
From 6da5b0506d6378a8dbe5ae314d5134e6868aeabd Mon Sep 17 00:00:00 2001
From: danigm <daniel.garcia@suse.com>
Date: Wed, 20 Dec 2023 16:02:13 +0100
Subject: [PATCH] Update expected message to match python 3.11.7 (#404)
https://github.com/python/cpython/issues/111019
Fixes #401.
Closes #403.
---
tests/test_pytest_mock.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py
index c185f2a..01534a4 100644
--- a/tests/test_pytest_mock.py
+++ b/tests/test_pytest_mock.py
@@ -25,6 +25,8 @@
# Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0
NEW_FORMATTING = sys.version_info >= (3, 8)
+# Python 3.11.7 changed the output formatting, https://github.com/python/cpython/issues/111019
+NEWEST_FORMATTING = sys.version_info >= (3, 11, 7)
if sys.version_info[:2] >= (3, 8):
from unittest.mock import AsyncMock
@@ -240,7 +242,9 @@ def test_repr_with_name(self, mocker: MockerFixture) -> None:
def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None:
expected_name = kwargs.get("name") or "mock"
- if NEW_FORMATTING:
+ if NEWEST_FORMATTING:
+ msg = "expected call not found.\nExpected: {0}()\n Actual: not called."
+ elif NEW_FORMATTING:
msg = "expected call not found.\nExpected: {0}()\nActual: not called."
else:
msg = "Expected call: {0}()\nNot called"

View File

@ -9,6 +9,9 @@ Summary: Thin-wrapper around the mock package for easier use with py.test
License: MIT License: MIT
URL: https://github.com/pytest-dev/pytest-mock/ URL: https://github.com/pytest-dev/pytest-mock/
Source0: %{pypi_source} Source0: %{pypi_source}
# https://github.com/pytest-dev/pytest-mock/pull/404
Patch0: 0001-Update-expected-message.patch
BuildArch: noarch BuildArch: noarch
%description %description