-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
unittest.mock._Call ignores name
parameter
#73147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
code in def __new__(cls, value=(), name=None, parent=None, two=False,
¦ ¦ ¦ from_kall=True):
¦ name = ''
¦ args = ()
¦ kwargs = {}
¦ _len = len(value)
¦ if _len == 3:
... the parameter |
That indeed looks like a bug. Well spotted :) That code has been there since unittest.mock was added back in March 2012. If I were to guess, I'd say that it should be |
_Call.__new__
in unittest.mock)?name
parameter
Thanks for reply :) the patch has been uploaded. |
update the patch file follow the doc(https://docs.python.org/devguide/gitdevs.html) |
The new patch has been updated. :) |
Thanks for the patch, Jiajun. The _Call class is tested in CallTest (located in Lib/unittest/test/testmock/testhelpers.py) Would it be possible to add a test case to make sure that we actually fixed the bug? |
I think we can write def __new__(cls, value=(), name='',...) it's much simpler and readable. |
code and test case has been updated. |
hi, do this need more test case or something else to be merged? please let me know :) |
Please remove "import ipdb; ipdb.set_trace() # TODO remove it" before posting patches ;-) |
sorry about that, fixed. |
The patch looks good to me. There are some styling issues in the test code (e.g. no need to add trailing spaces after commas in some cases), but I can take care of them before committing the patch :) Thanks! |
The latest patch (Jiajun Huang, 2017-01-03 14:34) LGTM. |
Yep, LGTM as well. Nicely spotted! |
New changeset 50424a903593 by Victor Stinner in branch '3.6': |
I applied the latest mock.patch to Python 3.6 and default (future 3.7). I prefer to wait for the 3.5.3 release before backporting the fix to 3.5, the fix is minor, I don't want to annoy the release manager yet. |
IIRC 3.5.3rc1 is already tagged so the 3.5 branch is open for 3.5.4. Anything that needs to be in 3.5.3 should be cherry-picked by the RM at this point if I'm not mistaken (and note that I don't have time check, but 3.5.3 may be the last bugfix release of 3.5 series so you may just skip 3.5 :)) Like I already said in msg284589, the test code doesn't follow the current style in Lib/unittest/test/testmock/testhelpers.py and it can be simplified like the following patch: def test_call_with_name(self):
- self.assertEqual(
- 'foo',
- _Call((), 'foo')[0],
- )
- self.assertEqual(
- '',
- _Call((('bar', 'barz'), ), )[0]
- )
- self.assertEqual(
- '',
- _Call((('bar', 'barz'), {'hello': 'world'}), )[0]
- )
+ self.assertEqual(_Call((), 'foo')[0], 'foo')
+ self.assertEqual(_Call((('bar', 'barz'),),)[0], '')
+ self.assertEqual(_Call((('bar', 'barz'), {'hello': 'world'}),)[0], '') |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: