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 functions with autospec don't support assert_called_once, assert_called, assert_not_called #72566

Closed
YannickBrehon mannequin opened this issue Oct 6, 2016 · 3 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@YannickBrehon
Copy link
Mannequin

YannickBrehon mannequin commented Oct 6, 2016

BPO 28380
Nosy @gpshead
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • fix_autospecced_mock_functions.patch: Patch for fixing the issue against head
  • 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/gpshead'
    closed_at = <Date 2016-10-06.21:35:57.302>
    created_at = <Date 2016-10-06.20:13:19.511>
    labels = ['3.7', 'type-bug', 'library']
    title = "Mock functions with autospec don't support assert_called_once, assert_called, assert_not_called"
    updated_at = <Date 2017-03-31.16:36:23.729>
    user = 'https://bugs.python.org/YannickBrehon'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:23.729>
    actor = 'dstufft'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2016-10-06.21:35:57.302>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2016-10-06.20:13:19.511>
    creator = 'Yannick Brehon'
    dependencies = []
    files = ['44991']
    hgrepos = []
    issue_num = 28380
    keywords = ['patch']
    message_count = 3.0
    messages = ['278208', '278213', '278214']
    nosy_count = 3.0
    nosy_names = ['gregory.p.smith', 'python-dev', 'Yannick Brehon']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28380'
    versions = ['Python 3.6', 'Python 3.7']

    @YannickBrehon
    Copy link
    Mannequin Author

    YannickBrehon mannequin commented Oct 6, 2016

    If one defines a mock for a function, using autospec=True, then the mock will correctly support assert_called_once_with(), among others, but not assert_called_once, assert_called, and assert_not_called.
    The attached file contains a fix for the issue.

    @YannickBrehon YannickBrehon mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 6, 2016
    @gpshead gpshead self-assigned this Oct 6, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 6, 2016

    New changeset 4e39b4e57673 by Gregory P. Smith in branch '3.6':
    Fixes bpo-28380: unittest.mock Mock autospec functions now properly support
    https://hg.python.org/cpython/rev/4e39b4e57673

    New changeset fca5c4a63251 by Gregory P. Smith in branch 'default':
    Issue bpo-28380: unittest.mock Mock autospec functions now properly support
    https://hg.python.org/cpython/rev/fca5c4a63251

    @gpshead
    Copy link
    Member

    gpshead commented Oct 6, 2016

    thanks! I didn't apply the fix to 3.5 (or earlier - those are closed) as it could arguably be seen as adding a new API and there are valid workarounds by asserting on the list of calls directly.

    @gpshead gpshead closed this as completed Oct 6, 2016
    @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
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant