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

unittest.mock.call can't represent calls to a method called 'parent' #79538

Closed
cjw296 opened this issue Nov 30, 2018 · 9 comments
Closed

unittest.mock.call can't represent calls to a method called 'parent' #79538

cjw296 opened this issue Nov 30, 2018 · 9 comments
Assignees

Comments

@cjw296
Copy link
Contributor

cjw296 commented Nov 30, 2018

BPO 35357
Nosy @cjw296, @voidspace, @mariocj89, @and3rson
PRs
  • bpo-35357: Add _mock_ prefix to mangle _Call/_MagicProxy attributes #10873
  • [3.7] bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (GH-10873) #10887
  • [3.6] bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (GH-10873) #10888
  • 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 = 'https://github.com/cjw296'
    closed_at = <Date 2018-12-04.09:35:25.217>
    created_at = <Date 2018-11-30.07:55:37.647>
    labels = []
    title = "unittest.mock.call can't represent calls to a method called 'parent'"
    updated_at = <Date 2018-12-04.09:35:25.217>
    user = 'https://github.com/cjw296'

    bugs.python.org fields:

    activity = <Date 2018-12-04.09:35:25.217>
    actor = 'cjw296'
    assignee = 'cjw296'
    closed = True
    closed_date = <Date 2018-12-04.09:35:25.217>
    closer = 'cjw296'
    components = []
    creation = <Date 2018-11-30.07:55:37.647>
    creator = 'cjw296'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35357
    keywords = ['patch']
    message_count = 9.0
    messages = ['330757', '330964', '330965', '330966', '330967', '330971', '331019', '331021', '331022']
    nosy_count = 4.0
    nosy_names = ['cjw296', 'michael.foord', 'mariocj89', 'and3rson']
    pr_nums = ['10873', '10887', '10888']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35357'
    versions = []

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Nov 30, 2018

    While working on https://bugs.python.org/issue35226, I stumbled upon this:

    >>> from unittest.mock import call
    >>> call.parent()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not callable

    Guess we need to make .parent and friends more uniquely named ;-)

    @cjw296 cjw296 self-assigned this Nov 30, 2018
    @and3rson
    Copy link
    Mannequin

    and3rson mannequin commented Dec 3, 2018

    I've just stumbled upon this issue while looking for a good first issue to contribute on. If the community agrees this is something that needs to be done, I'll gladly work on this.

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Dec 3, 2018

    Go for it! :-)

    @and3rson
    Copy link
    Mannequin

    and3rson mannequin commented Dec 3, 2018

    I see 2 most applicable ways to do it:

    • Hide .parent and .name by mangling
    • Define them within the mock class definition scope, but not within the class itself.

    As long as those are accessed only from within the mock class, I think second method would be better as it would completely remove them from mock's attributes.

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Dec 3, 2018

    Not sure I follow the second option, I was thinking of just _mock_parent and _mock_name when I logged this.

    Happy to see a PR for either though!

    @and3rson
    Copy link
    Mannequin

    and3rson mannequin commented Dec 3, 2018

    I was considering wrapping a unittest.mock._Call class definition within a function that would contain name & parent as local variables (arguments). Thus they would be accessible within the _Call class, but wouldn't be accessible from the outside. However this would make them inaccessible from other instances of _Call. So I think I'll stick to the more trivial solution of renaming them to _mock_name and _mock_parent to conform to the rest of the module :)

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Dec 4, 2018

    New changeset e63e617 by Chris Withers (Andrew Dunai) in branch 'master':
    bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (bpo-10873)
    e63e617

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Dec 4, 2018

    New changeset 12735c1 by Chris Withers (Miss Islington (bot)) in branch '3.7':
    bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (GH-10873) (bpo-10887)
    12735c1

    @cjw296
    Copy link
    Contributor Author

    cjw296 commented Dec 4, 2018

    New changeset 70ca3fc by Chris Withers (Miss Islington (bot)) in branch '3.6':
    bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (GH-10873)
    70ca3fc

    @cjw296 cjw296 closed this as completed Dec 4, 2018
    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant