Skip to content

Inconsistent behavior of pytest.deprecated_call() #1190

@netme

Description

@netme

We are currently upgrading py.test from 2.7.1 to 2.8.3 . We have found a small inconsistency in pytest.deprecated_call() behaviour.

We have few tests which are calling deprecated methods in our codebase. And afterwards we have few tests which are checking that the methods are deprecated. Running that tests on 2.7.1 produce no issues. After switching to 2.8.3, we have found out that the tests which are using pytest.deprecated_call() started failing. Here is an example:

import warnings

import pytest


def deprecated_function():
    warnings.warn("deprecated", DeprecationWarning)


def test_one():
    deprecated_function()


def test_two():
    pytest.deprecated_call(deprecated_function)

When running it on 2.8.3, the following AssertionError is raised:

    def test_two():
>       pytest.deprecated_call(deprecated_function)
E       AssertionError: <function deprecated_function at 0x10ac51a28> did not produce DeprecationWarning

On 2.7.1 it works fine.

Seems to be adding warnings.simplefilter('always') call before deprecated_function() call fixes the issue:

import warnings

import pytest


def deprecated_function():
    warnings.warn("deprecated", DeprecationWarning)


def test_one():
    warnings.simplefilter('always')
    deprecated_function()


def test_two():
    pytest.deprecated_call(deprecated_function)

Could you please check this small issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions