GeezerVison is showing github.com — 3.12.0a7 changes behavior of PropertyMock · Issue #103329 · python/cpython
3.12.0a7 changes behavior of PropertyMock #103329DescriptionBug report
3.12.0a7 changed the behavior of unittest.mock.PropertyMock
Setup:
from unittest.mock import MagicMock, PropertyMock
m = MagicMock()
p1 = PropertyMock(return_value=3)
p2 = PropertyMock(side_effect=ValueError)
type(m).foo = p1
type(m).bar = p2
In Python 3.12.0a6 and earlier, m.foo evaluates as 3, and m.bar raises a ValueError.
In Python 3.12.0a7, m.foo evaluates as 3, and m.bar returns <MagicMock name='mock.bar' id=...>
Your environment
- CPython versions tested on: 3.12.0a7, 3.12.0a6, 3.11.2, 3.10.10, 3.9.16, 3.8.16
- Operating system and architecture:
- macOS Ventura 13.2.1, on an M1 MacBook Pro.
- GitHub Actions macOS 12 x86_64
- GitHub Actions Ubuntu 22.04
- GitHub Actions Windows Server 2022
Linked PRs
Activitysunmy2019 commented on Apr 7, 2023 A known on-going failure was introduced in the related components: aa0a73d
See #103272
Can anyone test if it starts here? freakboy3742 commented on Apr 7, 2023 ContributorAuthor More actions @sunmy2019 I'm not sure aa0a73d is the cause here (or, at least, it isn't the only thing in play); in my testing, that commit still raises a ValueError - although the presentation is slightly different, as it also includes
>>> m.bar
Traceback (most recent call last):
File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 2957, in __get__
return self()
^^^^^^
File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1128, in __call__
return self._mock_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1132, in _mock_call
return self._execute_mock_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1187, in _execute_mock_call
raise effect
ValueError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 656, in __getattr__
if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <method 'startswith' of 'str' objects> returned a result with an exception set
whereas 3.11 et al raise:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 2932, in __get__
return self()
^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1118, in __call__
return self._mock_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1122, in _mock_call
return self._execute_mock_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1177, in _execute_mock_call
raise effect
ValueError
sunmy2019 commented on Apr 7, 2023 Looks like it was fixed by #103332
With current main, I got the same output as in your python3.11. @freakboy3742 carljm commented on Apr 7, 2023 Before closing this issue, we should add a test for this case that would have failed on the original breaking PR. freakboy3742 commented on Apr 8, 2023 ContributorAuthor More actions Confirming this has been fixed by #103332. I've submitted some regression tests in #103358.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|