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

Add FutureWarning to deprecated_call() #11447

Closed
chrimaho opened this issue Sep 18, 2023 · 3 comments · Fixed by #11448
Closed

Add FutureWarning to deprecated_call() #11447

chrimaho opened this issue Sep 18, 2023 · 3 comments · Fixed by #11448

Comments

@chrimaho
Copy link
Contributor

What's the problem this feature will solve?

When implementing deprecated features, we are regularly expected to use the DeprecationWarning and PendingDeprecationWarning warnings. However, there is another one: FutureWarning. This particular warning is used by packages such as pydeprecate as the default warning for any functions that will be removed in the future.

However, when I write a function that raises the FutureWarning (or use the @deprecated decorator), then deprecated_call() currently does not catch the test successfully.

Describe the solution you'd like

I'd like to add FutureWarning to the list of warnings which are captured by deprecated_call().

This is the current behaviour:

from warnings import warn
from pytest import deprecated_call

def deprecated_func():
    warn("This function is deprecated", DeprecationWarning)
    pass

def future_deprecation_func():
    warn("This function will be deprecated in the future", FutureWarning)
    pass

def test_deprecated():
    """Expected to pass"""
    with deprecated_call():
        deprecated_func()

def test_futures():
    """Expected to fail"""
    with deprecated_call():
        future_deprecation_func()

The expected behaviour would be for both of these two test cases to pass successfully.

Alternative Solutions

N/A

Additional context

N/A

@RonnyPfannschmidt
Copy link
Member

Closing as invalid, pydeprecate doesn't use warnings

As far as I'm concerned it's completely broken

@RonnyPfannschmidt RonnyPfannschmidt closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2023
@The-Compiler
Copy link
Member

@RonnyPfannschmidt ...huh? It sure does, and given the Python docs:

Base class for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python.

(emphasis mine), it seems perfectly reasonable to me to have pytest.deprecated_call() include that?

@RonnyPfannschmidt
Copy link
Member

i missed that alias

i think i need to get updated on what futurewarnings mean these days
as i have commonly seem them used for marking experimental code that may see changes in future (aka marking new features as experimental as opposed to

i indeed missed the alias to warn(category=...) when reading the code of the library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants