Merge pull request #1227 from nicoddemus/warn-deprecated-call

Add a note about how DeprecationWarning and PendingDeprecationWarning are treated differently
This commit is contained in:
Ronny Pfannschmidt 2015-12-06 10:52:58 +01:00
commit a4a12b8356
1 changed files with 12 additions and 4 deletions

View File

@ -41,6 +41,10 @@ additional information::
Alternatively, you can examine raised warnings in detail using the Alternatively, you can examine raised warnings in detail using the
:ref:`recwarn <recwarn>` fixture (see below). :ref:`recwarn <recwarn>` fixture (see below).
.. note::
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
differently; see :ref:`ensuring_function_triggers`.
.. _recwarn: .. _recwarn:
Recording warnings Recording warnings
@ -87,6 +91,9 @@ Each recorded warning has the attributes ``message``, ``category``,
class of the warning. The ``message`` is the warning itself; calling class of the warning. The ``message`` is the warning itself; calling
``str(message)`` will return the actual message of the warning. ``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_function_triggers:
@ -94,16 +101,17 @@ Ensuring a function triggers a deprecation warning
------------------------------------------------------- -------------------------------------------------------
You can also call a global helper for checking 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 import pytest
def test_global(): def test_global():
pytest.deprecated_call(myfunction, 17) pytest.deprecated_call(myfunction, 17)
By default, deprecation warnings will not be caught when using ``pytest.warns`` By default, ``DeprecationWarning`` and ``PendingDeprecationWarning`` will not be
or ``recwarn``, since the default Python warnings filters hide caught when using ``pytest.warns`` or ``recwarn`` because default Python warnings filters hide
DeprecationWarnings. If you wish to record them in your own code, use the them. If you wish to record them in your own code, use the
command ``warnings.simplefilter('always')``:: command ``warnings.simplefilter('always')``::
import warnings import warnings