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.patch.dict.__enter__ should return the dict #76480

Closed
AllenLi mannequin opened this issue Dec 13, 2017 · 4 comments
Closed

unittest.mock.patch.dict.__enter__ should return the dict #76480

AllenLi mannequin opened this issue Dec 13, 2017 · 4 comments
Labels
3.8 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@AllenLi
Copy link
Mannequin

AllenLi mannequin commented Dec 13, 2017

BPO 32299
Nosy @rbtcollins, @voidspace, @csabella, @tirkarthi
PRs
  • bpo-32299: unittest.mock.patch.dict now returns patched dict when used as context manager #4834
  • bpo-32299: Return patched dict when using patch.dict as a context manager #11062
  • 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 2019-05-28.12:59:19.049>
    created_at = <Date 2017-12-13.07:08:20.287>
    labels = ['3.8', 'type-feature', 'library']
    title = 'unittest.mock.patch.dict.__enter__ should return the dict'
    updated_at = <Date 2019-05-28.12:59:19.048>
    user = 'https://bugs.python.org/AllenLi'

    bugs.python.org fields:

    activity = <Date 2019-05-28.12:59:19.048>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-28.12:59:19.049>
    closer = 'cheryl.sabella'
    components = ['Library (Lib)']
    creation = <Date 2017-12-13.07:08:20.287>
    creator = 'Allen Li'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32299
    keywords = ['patch']
    message_count = 4.0
    messages = ['308188', '310489', '343772', '343775']
    nosy_count = 5.0
    nosy_names = ['rbcollins', 'michael.foord', 'cheryl.sabella', 'Allen Li', 'xtreak']
    pr_nums = ['4834', '11062']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32299'
    versions = ['Python 3.8']

    @AllenLi
    Copy link
    Mannequin Author

    AllenLi mannequin commented Dec 13, 2017

    mock.patch.dict.__enter__ should return the patched dict/mapping object.

    Currently it returns nothing (None).

    This would make setting up fixtures more convenient:

     with mock.patch.dict(some.thing):
       some.thing['foo'] = 'bar'
    
     with mock.patch.dict(some.thing) as x:
       x['foo'] = 'bar'

    @AllenLi AllenLi mannequin added 3.8 (EOL) end of life 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Dec 13, 2017
    @berkerpeksag berkerpeksag removed the 3.8 (EOL) end of life label Jan 23, 2018
    @voidspace
    Copy link
    Contributor

    This seems like a reasonable feature request.

    @csabella csabella added 3.8 (EOL) end of life and removed 3.7 (EOL) end of life labels Apr 12, 2019
    @csabella
    Copy link
    Contributor

    New changeset 0453081 by Cheryl Sabella (Mario Corchero) in branch 'master':
    bpo-32299: Return patched dict when using patch.dict as a context manager (GH-11062)
    0453081

    @csabella
    Copy link
    Contributor

    @allen Li, thank you for the report. And thank you, @vadim Tsander for the original pull request and @mariocj89 for reviving this. Also, thank you @eric.araujo for the review and approval. This has been merged!

    @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.8 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants