Skip to content

pytest deprecated_call contextmanager not always seeing warnings #2469

@reaperhulk

Description

@reaperhulk

This is present in the latest pytest (and several previous versions I tried). If you have a function that calls a function that raises a warning then the contextmanager will not capture that warning properly...but only if you've called the function without wrapping it in deprecated_call already.

import warnings

import pytest


def warn_me():
    warnings.warn("deprecated", PendingDeprecationWarning, stacklevel=2)


def i_call_warn_me():
    warn_me()


# Pass
def test_warn_me_check_deprecated_ctx_before_not_checking():
    with pytest.deprecated_call():
        i_call_warn_me()


# Pass
def test_warn_me_dont_check_warning():
    i_call_warn_me()


# Fail
def test_warn_me_check_deprecated_ctx():
    with pytest.deprecated_call():
        i_call_warn_me()


# Pass
def test_warn_me_check_deprecated():
    pytest.deprecated_call(i_call_warn_me)

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions