Skip to content

Commit

Permalink
Add a note about how DeprecationWarning and PendingDeprecationWarning…
Browse files Browse the repository at this point in the history
… are treated differently

Fix pytest-dev#1026
  • Loading branch information
nicoddemus committed Dec 5, 2015
1 parent 41f1979 commit b48a02f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions doc/en/recwarn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ additional information::
Alternatively, you can examine raised warnings in detail using the
:ref:`recwarn <recwarn>` fixture (see below).

.. note::
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
differently; see :ref:`ensuring_function_triggers`.

.. _recwarn:

Recording warnings
Expand Down Expand Up @@ -87,23 +91,27 @@ Each recorded warning has the attributes ``message``, ``category``,
class of the warning. The ``message`` is the warning itself; calling
``str(message)`` will return the actual message of the warning.

.. note::
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
differently; see :ref:`ensuring_function_triggers`.

.. _ensuring_function_triggers:

Ensuring a function triggers a deprecation warning
-------------------------------------------------------

You can also call a global helper for checking
that a certain function call triggers a ``DeprecationWarning``::
that a certain function call triggers a ``DeprecationWarning`` or
``PendingDeprecationWarning``::

import pytest

def test_global():
pytest.deprecated_call(myfunction, 17)

By default, deprecation warnings will not be caught when using ``pytest.warns``
or ``recwarn``, since the default Python warnings filters hide
DeprecationWarnings. If you wish to record them in your own code, use the
By default, ``DeprecationWarning`` and ``PendingDeprecationWarning`` will not be
caught when using ``pytest.warns`` or ``recwarn`` because default Python warnings filters hide
them. If you wish to record them in your own code, use the
command ``warnings.simplefilter('always')``::

import warnings
Expand Down

0 comments on commit b48a02f

Please sign in to comment.