pytest deprecated_call contextmanager not always seeing warnings

Created on 4 Jun 2017  路  3Comments  路  Source: pytest-dev/pytest

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)
warnings bug

Most helpful comment

Oh got it, thanks. I can reproduce it now. 馃憤

All 3 comments

Hmm that's strange, it passes for me on 3.1.1:

pytest .tmp\test_bar.py
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: C:\pytest, inifile: tox.ini
plugins: hypothesis-3.7.0
collected 4 items

.tmp\test_bar.py ....

========================== 4 passed in 0.01 seconds ===========================

Can you provide more information about your environment?

Oops sorry, that was foolish. I completely forgot to mention that these tests pass as expected on 3.4, 3.5, 3.6, but fail on 2.6, 2.7, and 3.3.

Oh got it, thanks. I can reproduce it now. 馃憤

Was this page helpful?
0 / 5 - 0 ratings