GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mock.patch decorating a generator returns a regular function. · Issue #71528 · python/cpython

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

New issue
Copy link
New issue
Copy link
Open
Open
mock.patch decorating a generator returns a regular function.#71528
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

shoshber
mannequin
opened on Jun 17, 2016
Issue body actions
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']

    Activity

    1. shoshber commented on Jun 17, 2016

      @shoshber
      shoshbermannequin
      on Jun 17, 2016
      MannequinAuthor
      More actions

      (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

    2. shoshber
      added
      testsTests in the Lib/test dirTests in the Lib/test dir
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jun 17, 2016
    3. terryjreedy commented on Jun 18, 2016

      @terryjreedy
      terryjreedy
      on Jun 18, 2016
      Member
      More actions

      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.

    4. rbtcollins commented on Jun 18, 2016

      @rbtcollins
      rbtcollins
      on Jun 18, 2016
      Member
      More actions

      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.

    5. rbtcollins
      changed the title [-]mock.patch decorator fails silently on generators[/-] [+]mock.patch decorating a generator returns a regular function.[/+] on Jun 18, 2016
    6. rbtcollins commented on Jun 18, 2016

      @rbtcollins
      rbtcollins
      on Jun 18, 2016
      Member
      More actions

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

    7. shoshber commented on Jun 18, 2016

      @shoshber
      shoshbermannequin
      on Jun 18, 2016
      MannequinAuthor
      More actions

      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.

    8. shoshber commented on Jun 18, 2016

      @shoshber
      shoshbermannequin
      on Jun 18, 2016
      MannequinAuthor
      More actions

      output

    9. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    10. serhiy-storchaka
      added this to Unittest & doctest issueson May 20, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      • Unittest & doctest issues
        Status
        No status
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.