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 objects do not freeze arguments they are called with #77490

Closed
slacknate mannequin opened this issue Apr 18, 2018 · 3 comments
Closed

Unittest Mock objects do not freeze arguments they are called with #77490

slacknate mannequin opened this issue Apr 18, 2018 · 3 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@slacknate
Copy link
Mannequin

slacknate mannequin commented Apr 18, 2018

BPO 33309
Nosy @rbtcollins, @ezio-melotti, @voidspace, @slacknate, @tirkarthi
Files
  • mock_issue.py: Reproduces described issue, assertion error raised when it should not be.
  • 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 2018-09-24.15:38:28.520>
    created_at = <Date 2018-04-18.15:53:04.431>
    labels = ['3.7', 'invalid', 'type-bug', 'library']
    title = 'Unittest Mock objects do not freeze arguments they are called with'
    updated_at = <Date 2018-09-24.15:38:28.519>
    user = 'https://github.com/slacknate'

    bugs.python.org fields:

    activity = <Date 2018-09-24.15:38:28.519>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-09-24.15:38:28.520>
    closer = 'xtreak'
    components = ['Library (Lib)']
    creation = <Date 2018-04-18.15:53:04.431>
    creator = 'slacknate'
    dependencies = []
    files = ['47539']
    hgrepos = []
    issue_num = 33309
    keywords = []
    message_count = 3.0
    messages = ['315456', '319816', '326253']
    nosy_count = 5.0
    nosy_names = ['rbcollins', 'ezio.melotti', 'michael.foord', 'slacknate', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33309'
    versions = ['Python 3.7']

    @slacknate
    Copy link
    Mannequin Author

    slacknate mannequin commented Apr 18, 2018

    It is possible to make a call with a Mock object, for example, where a dictionary is passed to the mock and later modified. If a call assertion is then made against the mock using the initial value/contents of the dictionary the assertion will fail.

    @slacknate slacknate mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 18, 2018
    @tirkarthi
    Copy link
    Member

    Thanks for the issue. I think this is documented here : https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-arguments

    Thanks

    @tirkarthi
    Copy link
    Member

    Thanks for the details. As part of triaging I am closing this as not a bug since passing mutable arguments to a mock object and modifying it is a documented behavior at https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-arguments . Feel free to reopen this if needed.

    Thanks

    @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