Skip to content

pytest deprecated_call contextmanager not always seeing warnings #2469

Closed

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)

Activity

  1. nicoddemus commented on Jun 4, 2017

    @nicoddemus
    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?

  2. reaperhulk commented on Jun 4, 2017

    @reaperhulk
    ContributorAuthor

    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.

  3. nicoddemus commented on Jun 4, 2017

    @nicoddemus
    Member

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

  4. added 2 commits that reference this issue on Jun 7, 2017
    a409ee3
    620ba59
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: 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