From 6089230d3ec580f2f44e85f23962c14905fefcfd Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Tue, 21 Nov 2023 17:13:08 +0000 Subject: Refs #34986 -- Fixed mocking in utils_tests.test_http.HttpDateProcessingTests.test_parsing_rfc850. Mocking in the `datetime` module can be tricky. In CPython the datetime C module is used, but PyPy uses a pure Python implementation. This caused issues with the prior approach to mocking `datetime.datetime`. See https://docs.python.org/3/library/unittest.mock-examples.html#partial-mocking --- tests/utils_tests/test_http.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/utils_tests') diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index 818c35e597..68df04696a 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -334,10 +334,9 @@ class HttpDateProcessingTests(unittest.TestCase): ) @unittest.skipIf(platform.architecture()[0] == "32bit", "The Year 2038 problem.") - @mock.patch("django.utils.http.datetime.datetime") + @mock.patch("django.utils.http.datetime") def test_parsing_rfc850(self, mocked_datetime): mocked_datetime.side_effect = datetime - mocked_datetime.now = mock.Mock() now_1 = datetime(2019, 11, 6, 8, 49, 37, tzinfo=timezone.utc) now_2 = datetime(2020, 11, 6, 8, 49, 37, tzinfo=timezone.utc) now_3 = datetime(2048, 11, 6, 8, 49, 37, tzinfo=timezone.utc) -- cgit v1.3