Skip to content

Replace raise StopIteration with return - adhere to Pep 479  #2160

Closed

Description

@goodboy

As per pytest-dev/pluggy#38 and pep 479, it seems that some pluggy hook wrappers implemented in pytest are still using the soon to be deprecated raise StopIteration mechanism to signal early generator termination.

An example would be pytest_pycollect_makeitem.

As indicated in the pep all such usage should be changed to simple returns in Py3.6+.

Activity

  1. RonnyPfannschmidt commented on Dec 24, 2016

    @RonnyPfannschmidt
    Member

    its impossible to fix this as of now due to support for old python versions

  2. goodboy commented on Dec 25, 2016

    @goodboy
    Author

    @RonnyPfannschmidt I'm not sure that's true?

    Supposedly all code can be made backwards compatible even in Py2.6 as per the original generator's Pep 255. Maybe I'm forgetting something though?

  3. RonnyPfannschmidt commented on Dec 26, 2016

    @RonnyPfannschmidt
    Member

    @tgoodlet indeed, the example looks perfectly valid to convert, i may have been overly pessimistic
    we should go and try at least, perhaps we can convert everything just fine

  4. nicoddemus commented on Dec 27, 2016

    @nicoddemus
    Member

    Unless I'm missing something (and that's a possibility since I didn't read PEP-479 thoroughly), can we just replace the raise StopIteration by a return?

    This patch seems to work fine in Py2.6, 2.7 and 3.5:

    diff --git a/_pytest/python.py b/_pytest/python.py
    index e46f2f1..2973d43 100644
    --- a/_pytest/python.py
    +++ b/_pytest/python.py
    @@ -174,7 +174,7 @@ def pytest_pycollect_makeitem(collector, name, obj):
         outcome = yield
         res = outcome.get_result()
         if res is not None:
    -        raise StopIteration
    +        return
         # nothing was collected elsewhere, let's do it here
         if isclass(obj):
             if collector.istestclass(obj, name):
  5. goodboy commented on Dec 28, 2016

    @goodboy
    Author

    @RonnyPfannschmidt Sounds good :)
    @nicoddemus Yep you've got it.

    You guys want me to make a PR?

  6. nicoddemus commented on Dec 28, 2016

    @nicoddemus
    Member

    Please go ahead. 😁 Thanks!

  7. added a commit that references this issue on Feb 1, 2017
    e1c5314
  8. tiran commented on Feb 1, 2017

    @tiran

    The problem is causing test failures in Custodia on Python 3.6. The test turn all deprecation warnings into fatal failures. For Custodia I put a band-aid on the issue and filter out deprecation warnings from '_pytest\..*'.

    latchset/custodia#105 (comment)

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

    type: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelog

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions