Skip to content

Change deprecation mechanism to use a function #7480

Closed

Description

@nicoddemus

As discussed in #7362 (comment)_, let's change our warnings mechanism to include a new PytestExpiredDeprecationWarning exception which is chosen at runtime depending on the current pytest version.

This will simplify our side because we won't need to change PytestDeprecationWarnings into errors anymore before each major release.

Activity

  1. added this to the 6.1 milestone on Jul 11, 2020
  2. nicoddemus commented on Jul 11, 2020

    @nicoddemus
    MemberAuthor

    Also, test_deprecation_warning_as_error will probably be removed.

  3. nicoddemus commented on Jul 11, 2020

    @nicoddemus
    MemberAuthor

    I'll be reverting these entries from the CHANGELOG:

    - `#6981 <https://github.com/pytest-dev/pytest/issues/6981>`_: Deprecate the ``pytest.collect`` module as it's just aliases into ``pytest``.
    
    
    - `#7097 <https://github.com/pytest-dev/pytest/issues/7097>`_: The ``pytest._fillfuncargs`` function is now deprecated. This function was kept
      for backward compatibility with an older plugin.
    
      It's functionality is not meant to be used directly, but if you must replace
      it, use `function._request._fillfixtures()` instead, though note this is not
      a public API and may break in the future.
    

    EDIT: done in #7482

  4. nicoddemus commented on Aug 21, 2020

    @nicoddemus
    MemberAuthor

    @RonnyPfannschmidt I just realized something.

    The plan here is to have a function somewhat like this:

    def deprecated(reason: str, *, due: int, stacklevel: int):
        if due >= pytest version [0]:
            warnings.warn(PytestExpiredDeprecationWarning(reason), stacklevel=stacklevel)
        else:
            warnings.warn(PytestDeprecationWarning(reason), stacklevel=stacklevel)

    Usage:

    def use_of_deprecated_thing():
       deprecated("don't use this function, use X instead", due=7)
       # do its thing

    However, because our version depends on the tag of the release, the actual pytest version will stay 6.X until the actual tag 7.0.0 is pushed at release time, and in that moment that function will issue PytestExpiredDeprecationWarning, which will then break the actual release. Any ideas?

  5. RonnyPfannschmidt commented on Aug 21, 2020

    @RonnyPfannschmidt
    Member

    For implementation towncrier support in setuptools_scm is intended and planned

  6. nicoddemus commented on Aug 21, 2020

    @nicoddemus
    MemberAuthor

    For implementation towncrier support in setuptools_scm is intended and planned

    Not sure what you mean, can you elaborate please?

  7. graingert commented on Aug 21, 2020

    @graingert
    Member

    Remember the stacklevel for warnings.warn:

    def deprecated(reason: str, *, due: int, stacklevel=0):
        stacklevel = stacklevel + 1
        if due >= pytest version [0]:
            warnings.warn(PytestExpiredDeprecationWarning(reason), stacklevel=stacklevel)
        else:
            warnings.warn(PytestDeprecationWarning(reason), stacklevel=stacklevel)
    
  8. RonnyPfannschmidt commented on Aug 21, 2020

    @RonnyPfannschmidt
    Member

    I strongly oppose combining declaration and triggering of warnings

  9. RonnyPfannschmidt commented on Aug 21, 2020

    @RonnyPfannschmidt
    Member

    @nicoddemus if the next guessed version is based on semver + towncrier inference, it's 7.0.dev... As soon as a breaking change is merged

  10. nicoddemus commented on Aug 21, 2020

    @nicoddemus
    MemberAuthor

    I strongly oppose combining declaration and triggering of warnings

    Noted, just to get this out of the way then:

    def deprecated_warning(reason: str, *, due: int) -> PytestWarning:
        if due >= pytest version [0]:
            return PytestExpiredDeprecationWarning(reason)
        else:
            return PytestDeprecationWarning(reason)

    @nicoddemus if the next guessed version is based on semver + towncrier inference, it's 7.0.dev... As soon as a breaking change is merged

    Ahh I see, thanks.

    Should we hold this issue until that happens then?

  11. RonnyPfannschmidt commented on Aug 21, 2020

    @RonnyPfannschmidt
    Member

    Yup

  12. nicoddemus commented on Aug 21, 2020

    @nicoddemus
    MemberAuthor

    Ahh I found it: pypa/setuptools-scm#332

    OK then, let's hold then.

  13. removed this from the 6.1 milestone on Aug 21, 2020
  14. bluetech commented on Aug 22, 2020

    @bluetech
    Member

    This will simplify our side because we won't need to change PytestDeprecationWarnings into errors anymore before each major release.

    Is this a major headache? Making things conditional on our own __version__ might cause some headaches of its own...


    BTW, Django does something I like, which is embed the removal version in the warning type. This brings clarity to all involved, but might be getting too fancy.

    Adapted to pytest (as of version 6.1), this would be:

    # Existing class
    class PytestDeprecationWarning(PytestWarning, DeprecationWarning): ...
    
    # New class
    class PytestExpiredDeprecationWarning(PytestWarning, DeprecationWarning): ...
    
    # New class
    class PytestPendingDeprecationWarning(PytestWarning, PendingDeprecationWarning): ...
    class PytestRemovedInPytest7Warning(PytestDeprecationWarning): ...
    
    class PytestRemovedInPytest8Warning(PytestPendingDeprecationWarning): ...

    When pytest 7 is released, changes to

    class PytestRemovedInPytest7Warning(PytestExpiredDeprecationWarning): ...
    
    class PytestRemovedInPytest8Warning(PytestDeprecationWarning): ...
    
    class PytestRemovedInPytest9Warning(PytestPendingDeprecationWarning): ...

    When pytest 7.1 is released, changes to

    class PytestRemovedInPytest8Warning(PytestDeprecationWarning): ...
    
    class PytestRemovedInPytest9Warning(PytestPendingDeprecationWarning): ...

    The PytestDeprecationWarning should be used when adding deprecations right before a major release (when we had this case in pytest 6.0, we disabled them until after the release instead).

  15. RonnyPfannschmidt commented on Aug 22, 2020

    @RonnyPfannschmidt
    Member

    based on experiences in pip and a few internal tools, the self version dependency seems orders of magnitude better than any manually managed way to deal with it

  16. added a commit that references this issue on Nov 14, 2021
    128f29e
  17. added a commit that references this issue on Feb 5, 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

    plugin: warningsrelated to the warnings builtin plugintype: deprecationfeature that will be removed in the future

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions