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.patch decorating a generator returns a regular function. #71528

Open
shoshber mannequin opened this issue Jun 17, 2016 · 6 comments
Open

mock.patch decorating a generator returns a regular function. #71528

shoshber mannequin opened this issue Jun 17, 2016 · 6 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@shoshber
Copy link
Mannequin

shoshber mannequin commented Jun 17, 2016

BPO 27341
Nosy @terryjreedy, @rbtcollins, @voidspace, @shoshber, @tirkarthi
Files
  • silentfail.py: example tests
  • actual.out: output
  • 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 = None
    created_at = <Date 2016-06-17.05:35:08.841>
    labels = ['type-bug', 'tests']
    title = 'mock.patch decorating a generator returns a regular function.'
    updated_at = <Date 2019-12-13.11:13:51.134>
    user = 'https://github.com/shoshber'

    bugs.python.org fields:

    activity = <Date 2019-12-13.11:13:51.134>
    actor = 'xtreak'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tests']
    creation = <Date 2016-06-17.05:35:08.841>
    creator = 'shoshber'
    dependencies = []
    files = ['43443', '43444']
    hgrepos = []
    issue_num = 27341
    keywords = []
    message_count = 6.0
    messages = ['268709', '268749', '268757', '268758', '268761', '268762']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'rbcollins', 'michael.foord', 'shoshber', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27341'
    versions = ['Python 3.5', 'Python 3.6']

    @shoshber
    Copy link
    Mannequin Author

    shoshber mannequin commented Jun 17, 2016

    (at least in my case)

    I committed two tests before I realized the tests were not being run: https://github.com/nipy/nipype/blob/abe7920a051f1570ccce4b71f26f50102d6e4e12/nipype/testing/tests/test_utils.py#L23

    I realized this afternoon, while writing some more tests, that tests with the patch decorator were all reported as "OK", even when I wanted them to fail. Turns out they aren't being run at all.

    I commented out all the yield statements, and the tests ran just as they should.

    I don't know exactly what is going on here, but might raising an error or warning be good here?

    Originally filed here: testing-cabal/mock#366

    @shoshber shoshber mannequin added tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Jun 17, 2016
    @terryjreedy
    Copy link
    Member

    3.2 to 3.4 only get security fixes

    please provide a simple test that fails now and that you think should pass or at least warn.

    @rbtcollins
    Copy link
    Member

    There are two related things here.

    Firstly, the generator's body will run without the patch (because the wrapping function has

    try:
    return decorated(..)
    finally:
    unpwatch()

    Secondly, the wrapping function is itself not a generator, and anything that introspects functions to see if they are generators will not detect the wrapped function as one - which is I suspect whats tripping nose up, but I haven't actually checked the nose code to see what its doing/expecting.

    @rbtcollins rbtcollins changed the title mock.patch decorator fails silently on generators mock.patch decorating a generator returns a regular function. Jun 18, 2016
    @rbtcollins
    Copy link
    Member

    Once fixed in CPython, we'll put the backport in mock, for folk using older Python's.

    @shoshber
    Copy link
    Mannequin Author

    shoshber mannequin commented Jun 18, 2016

    I attached a file with 4 tests and the output. nosetests reports that all four tests were executed. In reality, only two tests were executed.

    @shoshber
    Copy link
    Mannequin Author

    shoshber mannequin commented Jun 18, 2016

    output

    @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
    tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants