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

pytest deprecated_call contextmanager not always seeing warnings #2469

Closed
reaperhulk opened this issue Jun 4, 2017 · 3 comments
Closed

pytest deprecated_call contextmanager not always seeing warnings #2469

reaperhulk opened this issue Jun 4, 2017 · 3 comments
Labels
plugin: warnings related to the warnings builtin plugin type: bug problem that needs to be addressed

Comments

@reaperhulk
Copy link
Contributor

reaperhulk commented Jun 4, 2017

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)
@nicoddemus
Copy link
Member

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?

@reaperhulk
Copy link
Contributor Author

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.

@nicoddemus
Copy link
Member

Oh got it, thanks. I can reproduce it now. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants