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 object has inherited count method #65469

Closed
voidspace opened this issue Apr 16, 2014 · 7 comments
Closed

unittest.mock.call object has inherited count method #65469

voidspace opened this issue Apr 16, 2014 · 7 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@voidspace
Copy link
Contributor

BPO 21270
Nosy @voidspace, @kushaldas
Files
  • issue21270.patch: Patch to override touple methods.
  • issue21270_v2.patch: Patch to override touple methods version 2.
  • 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/voidspace'
    closed_at = <Date 2014-09-16.13:04:18.970>
    created_at = <Date 2014-04-16.20:49:19.418>
    labels = ['type-bug']
    title = 'unittest.mock.call object has inherited count method'
    updated_at = <Date 2014-09-16.13:04:18.968>
    user = 'https://github.com/voidspace'

    bugs.python.org fields:

    activity = <Date 2014-09-16.13:04:18.968>
    actor = 'python-dev'
    assignee = 'michael.foord'
    closed = True
    closed_date = <Date 2014-09-16.13:04:18.970>
    closer = 'python-dev'
    components = []
    creation = <Date 2014-04-16.20:49:19.418>
    creator = 'michael.foord'
    dependencies = []
    files = ['36581', '36630']
    hgrepos = []
    issue_num = 21270
    keywords = ['patch']
    message_count = 7.0
    messages = ['216587', '222546', '222562', '226634', '226803', '226950', '226951']
    nosy_count = 3.0
    nosy_names = ['michael.foord', 'python-dev', 'kushal.das']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21270'
    versions = ['Python 3.5']

    @voidspace
    Copy link
    Contributor Author

    The unittest.mock.call object inherits methods from tuple that prevent you using them as normal call attributes. They should be overridden.

    @voidspace voidspace self-assigned this Apr 16, 2014
    @voidspace voidspace added the type-bug An unexpected behavior, bug, or error label Apr 16, 2014
    @kushaldas
    Copy link
    Member

    To start with I am overriding count and index method. Do you think this is enough?

    @voidspace
    Copy link
    Contributor Author

    Those are the only ones I think. Thanks.

    @kushaldas
    Copy link
    Member

    Forgot to attach the patch. Includes NEWS entry. Overriden methods count() and index().

    @voidspace
    Copy link
    Contributor Author

    Thanks for this Kushal. It's not quite right though, count and index need to do the same as other attributes looked up with __getattr__. In fact delegating to __getattr__ is probably the easiest way of achieving that. (With the current patch the calls will be incorrect for call.foo.index() or similar I believe.)

    @kushaldas
    Copy link
    Member

    Uploading the second version of the patch.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 16, 2014

    New changeset 5660c1bdc2b6 by Kushal Das in branch 'default':
    Closes bpo-21270 : We now override tuple methods in mock.call objects.
    https://hg.python.org/cpython/rev/5660c1bdc2b6

    @python-dev python-dev mannequin closed this as completed Sep 16, 2014
    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants