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

make unittest.mock.mock_open honor next() #81189

Closed
Anvil mannequin opened this issue May 22, 2019 · 3 comments
Closed

make unittest.mock.mock_open honor next() #81189

Anvil mannequin opened this issue May 22, 2019 · 3 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@Anvil
Copy link
Mannequin

Anvil mannequin commented May 22, 2019

BPO 37008
Nosy @cjw296, @voidspace, @lisroach, @mariocj89, @miss-islington, @Anvil
PRs
  • bpo-37008: make mock_open handle able to honor next() #13492
  • [3.7] bpo-37008: make mock_open handle able to honor next() (GH-13492) #13521
  • 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-23.10:52:12.049>
    created_at = <Date 2019-05-22.11:19:07.062>
    labels = ['3.7', '3.8', 'type-feature', 'library']
    title = 'make unittest.mock.mock_open honor next()'
    updated_at = <Date 2019-05-23.10:52:12.048>
    user = 'https://github.com/Anvil'

    bugs.python.org fields:

    activity = <Date 2019-05-23.10:52:12.048>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-23.10:52:12.049>
    closer = 'asvetlov'
    components = ['Library (Lib)']
    creation = <Date 2019-05-22.11:19:07.062>
    creator = 'Anvil'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37008
    keywords = ['patch']
    message_count = 3.0
    messages = ['343177', '343283', '343284']
    nosy_count = 6.0
    nosy_names = ['cjw296', 'michael.foord', 'lisroach', 'mariocj89', 'miss-islington', 'Anvil']
    pr_nums = ['13492', '13521']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37008'
    versions = ['Python 3.7', 'Python 3.8']

    @Anvil
    Copy link
    Mannequin Author

    Anvil mannequin commented May 22, 2019

    While we can iterate on a mock_open handle, it is not actually possible to perform a next() on it.

    My use case is the following: I have a file with a one-line header that I want to skip. So, roughly, my code is like

        with open(filename, 'r') as my_file:
            confirm_header(next(my_file))
            for line in my_file:
                do_something(line)

    And while writing a unit test on this code, the handle returned by mock_open(read_data=my_read_data) returns a mock instead of the first line of my_read_data.

    @Anvil Anvil mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 22, 2019
    @tirkarthi tirkarthi removed the 3.7 (EOL) end of life label May 22, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset 394119a by Miss Islington (bot) (Damien Nadé) in branch 'master':
    bpo-37008: make mock_open handle able to honor next() (GH-13492)
    394119a

    @miss-islington
    Copy link
    Contributor

    New changeset 7cc47e9 by Miss Islington (bot) in branch '3.7':
    bpo-37008: make mock_open handle able to honor next() (GH-13492)
    7cc47e9

    @asvetlov asvetlov added the 3.7 (EOL) end of life label May 23, 2019
    @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 3.8 only security fixes 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