
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-01-24 17:20 byberdario, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| test_mock.py | chillaranand,2015-03-23 12:37 | sample test | ||
| fix_magic_in_init.diff | kjachim,2015-04-13 15:26 | Tests for this bug + proposed fix. | review | |
| fix_magic_in_init_v2.diff | kjachim,2015-04-13 15:55 | review | ||
| Messages (8) | |||
|---|---|---|---|
| msg234623 -(view) | Author: (berdario) | Date: 2015-01-24 17:20 | |
I guess this should be expected... too much magic :P>>> from unittest.mock import MagicMock>>> MagicMock(**{'__hash__.return_value': "FIXME"})Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 1772, in __init__ _safe_super(MagicMixin, self).__init__(*args, **kw) File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 881, in __init__ _spec_state, _new_name, _new_parent, **kwargs File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 410, in __init__ self.configure_mock(**kwargs) File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 560, in configure_mock setattr(obj, final, val)AttributeError: 'method-wrapper' object has no attribute 'return_value'The same happens with e.g. __str__>>> m.configure_mock(**{'__hash__.return_value': 1})works just fine, instead | |||
| msg239013 -(view) | Author: Anand Reddy Pandikunta (chillaranand)* | Date: 2015-03-23 12:37 | |
mock itself fails | |||
| msg240623 -(view) | Author: Kasia Jachim (kjachim) | Date: 2015-04-13 15:26 | |
Tests for this bug + proposed fix. | |||
| msg240626 -(view) | Author: Kasia Jachim (kjachim) | Date: 2015-04-13 15:39 | |
For Mock both the following tests fail, I would say it is an expected behavior.def test_setting_magic_method_for_mock(self): m = Mock() m.configure_mock(**{'__str__.return_value': "14"}) self.assertEqual(str(m), "14") def test_setting_magic_method_in_mock_initialization(self): m = Mock(**{'__str__.return_value': "12"}) self.assertEqual(str(m), "12") | |||
| msg240631 -(view) | Author: Kasia Jachim (kjachim) | Date: 2015-04-13 15:55 | |
Added more logging to the patch. | |||
| msg240844 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2015-04-14 06:12 | |
New changeset4d1236b180be by Łukasz Langa in branch 'default':Issue#23310: Fix MagicMock's initializer to work with __methods__.https://hg.python.org/cpython/rev/4d1236b180be | |||
| msg240853 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2015-04-14 07:17 | |
New changeset8e5592a43d65 by Łukasz Langa in branch '3.4':Issue#23310: Fix MagicMock's initializer to work with __methods__.https://hg.python.org/cpython/rev/8e5592a43d65New changesetdd8f48ff9480 by Łukasz Langa in branch 'default':Merge 3.4 (#23310)https://hg.python.org/cpython/rev/dd8f48ff9480 | |||
| msg240854 -(view) | Author: Łukasz Langa (lukasz.langa)*![]() | Date: 2015-04-14 07:19 | |
Awesome! Thank you for your patch, Kasia. For the record, I left the non-magic Mock behavior untouched since Kasia rightfully points out that in this case m.configure_mock() also does not work. | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:12 | admin | set | github: 67499 |
| 2015-04-14 07:24:37 | lukasz.langa | set | stage: needs patch -> resolved |
| 2015-04-14 07:19:28 | lukasz.langa | set | status: open -> closed title: Mock constructor configuration fails for magic methods -> MagicMock initializer fails for magic methods messages: +msg240854 keywords: -needs review resolution: fixed |
| 2015-04-14 07:17:18 | python-dev | set | messages: +msg240853 |
| 2015-04-14 06:12:57 | python-dev | set | nosy: +python-dev messages: +msg240844 |
| 2015-04-13 16:46:45 | lukasz.langa | set | keywords: +needs review versions: + Python 3.5 |
| 2015-04-13 16:04:42 | lukasz.langa | set | assignee:lukasz.langa nosy: +lukasz.langa |
| 2015-04-13 15:55:03 | kjachim | set | files: +fix_magic_in_init_v2.diff messages: +msg240631 |
| 2015-04-13 15:39:41 | kjachim | set | messages: +msg240626 |
| 2015-04-13 15:26:00 | kjachim | set | files: +fix_magic_in_init.diff nosy: +kjachim messages: +msg240623 keywords: +patch |
| 2015-03-23 12:37:33 | chillaranand | set | files: +test_mock.py title: MagicMock constructor configuration fails for magic methods -> Mock constructor configuration fails for magic methods nosy: +chillaranand messages: +msg239013 |
| 2015-03-16 03:04:48 | rbcollins | set | type: crash -> behavior |
| 2015-03-16 02:52:13 | rbcollins | set | type: crash stage: needs patch |
| 2015-03-03 22:43:01 | ned.deily | set | nosy: +rbcollins,michael.foord |
| 2015-01-24 17:20:39 | berdario | create | |