Skip to content
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

Mock create_autospec with name argument fails #65421

Closed
kushaldas opened this issue Apr 14, 2014 · 7 comments
Closed

Mock create_autospec with name argument fails #65421

kushaldas opened this issue Apr 14, 2014 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@kushaldas
Copy link
Member

BPO 21222
Nosy @voidspace, @kushaldas, @zooba
PRs
  • [3.9] bpo-41162: Fix improperly merged change so that final hooks are called before types are cleared #21304
  • Files
  • issue21222.patch
  • issue21222_v2.patch: New patchset with changes made as suggested.
  • Note: 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:

    assignee = None
    closed_at = <Date 2014-04-15.19:53:09.280>
    created_at = <Date 2014-04-14.19:54:11.031>
    labels = ['type-bug', 'library']
    title = 'Mock create_autospec with name argument fails'
    updated_at = <Date 2020-07-03.22:34:53.238>
    user = 'https://github.com/kushaldas'

    bugs.python.org fields:

    activity = <Date 2020-07-03.22:34:53.238>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-04-15.19:53:09.280>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2014-04-14.19:54:11.031>
    creator = 'kushal.das'
    dependencies = []
    files = ['34854', '34881']
    hgrepos = []
    issue_num = 21222
    keywords = ['patch']
    message_count = 7.0
    messages = ['216190', '216230', '216311', '216343', '216367', '216371', '372968']
    nosy_count = 4.0
    nosy_names = ['michael.foord', 'python-dev', 'kushal.das', 'steve.dower']
    pr_nums = ['21304']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21222'
    versions = ['Python 3.5']

    @kushaldas
    Copy link
    Member Author

    >>> from unittest import mock
    >>> def b():
    ...   print("hello")
    ... 
    >>> q = mock.create_autospec(b, name="a")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/kdas/code/python/cpython3/Lib/unittest/mock.py", line 2092, in create_autospec
        name=_name, **_kwargs)
    TypeError: type object got multiple values for keyword argument 'name'

    The issue was originally reported on mock bug tracker. I am working on a patch for the same.

    @kushaldas kushaldas added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 14, 2014
    @kushaldas
    Copy link
    Member Author

    Fix for the issue with test case. We are checking name in keyword arguments, if found replace _name with it and delete it from keyword arguments.

    @voidspace
    Copy link
    Contributor

    You can use kwargs.pop instead of the two step fetch and delete.

    For the test, could you add an assert that the name is used. Can you add an extra underscore to the method name, to make it: test_create_autospec_with_name

    @kushaldas
    Copy link
    Member Author

    New patchset with changes made as suggested.

    @voidspace
    Copy link
    Contributor

    Looks good to me, but please change qobj and add a NEWS entry.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 15, 2014

    New changeset d471b0d38516 by Kushal Das in branch '3.4':
    Closes bpo-21222.
    http://hg.python.org/cpython/rev/d471b0d38516

    @python-dev python-dev mannequin closed this as completed Apr 15, 2014
    @zooba
    Copy link
    Member

    zooba commented Jul 3, 2020

    New changeset 941117a by Steve Dower in branch '3.9':
    bpo-21222: Fix improperly merged change so that final hooks are called before types are cleared (GH-21304)
    941117a

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants