2009-07-21 00:54:08 +08:00
|
|
|
|
|
|
|
helpers for asserting deprecation and other warnings.
|
2010-01-13 23:00:33 +08:00
|
|
|
=====================================================
|
|
|
|
|
2009-07-21 00:54:08 +08:00
|
|
|
|
2009-07-22 22:09:49 +08:00
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
|
|
|
|
Example usage
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
You can use the ``recwarn`` funcarg to track
|
|
|
|
warnings within a test function:
|
|
|
|
|
|
|
|
.. sourcecode:: python
|
|
|
|
|
|
|
|
def test_hello(recwarn):
|
|
|
|
from warnings import warn
|
|
|
|
warn("hello", DeprecationWarning)
|
|
|
|
w = recwarn.pop(DeprecationWarning)
|
|
|
|
assert issubclass(w.category, DeprecationWarning)
|
|
|
|
assert 'hello' in str(w.message)
|
|
|
|
assert w.filename
|
|
|
|
assert w.lineno
|
|
|
|
|
|
|
|
You can also call a global helper for checking
|
|
|
|
taht a certain function call yields a Deprecation
|
|
|
|
warning:
|
|
|
|
|
|
|
|
.. sourcecode:: python
|
|
|
|
|
|
|
|
import py
|
|
|
|
|
|
|
|
def test_global():
|
|
|
|
py.test.deprecated_call(myfunction, 17)
|
2009-07-21 00:54:08 +08:00
|
|
|
|
|
|
|
.. _`recwarn funcarg`:
|
|
|
|
|
|
|
|
|
|
|
|
the 'recwarn' test function argument
|
|
|
|
------------------------------------
|
|
|
|
|
2009-07-22 22:09:49 +08:00
|
|
|
Return a WarningsRecorder instance that provides these methods:
|
|
|
|
|
|
|
|
* ``pop(category=None)``: return last warning matching the category.
|
|
|
|
* ``clear()``: clear list of warnings
|
2009-07-21 00:54:08 +08:00
|
|
|
|
2009-07-22 22:09:49 +08:00
|
|
|
Start improving this plugin in 30 seconds
|
|
|
|
=========================================
|
2009-07-21 00:54:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
1. Download `pytest_recwarn.py`_ plugin source code
|
|
|
|
2. put it somewhere as ``pytest_recwarn.py`` into your import path
|
2009-07-22 22:09:49 +08:00
|
|
|
3. a subsequent ``py.test`` run will use your local version
|
2009-07-21 00:54:08 +08:00
|
|
|
|
2009-08-19 01:04:57 +08:00
|
|
|
Checkout customize_, other plugins_ or `get in contact`_.
|
2009-07-21 00:54:08 +08:00
|
|
|
|
2009-07-31 20:43:04 +08:00
|
|
|
.. include:: links.txt
|