summaryrefslogtreecommitdiff
path: root/doc/en/recwarn.rst
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2015-08-04 16:41:02 +0530
committerAbhijeet Kasurde <akasurde@redhat.com>2015-08-04 16:41:02 +0530
commite79413acc403b3ef69b9ac5741b18768f706a779 (patch)
tree544edbe09755e72b95b6375777df59f0ce4a4db3 /doc/en/recwarn.rst
parentc605cf92f96d687dc7c0e67c933677085b4afcc4 (diff)
downloadpytest-e79413acc403b3ef69b9ac5741b18768f706a779.tar.gz
Updated documentation from txt to rst
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'doc/en/recwarn.rst')
-rw-r--r--doc/en/recwarn.rst46
1 files changed, 46 insertions, 0 deletions
diff --git a/doc/en/recwarn.rst b/doc/en/recwarn.rst
new file mode 100644
index 000000000..c07a2cbe7
--- /dev/null
+++ b/doc/en/recwarn.rst
@@ -0,0 +1,46 @@
+
+Asserting deprecation and other warnings
+=====================================================
+
+.. _function_argument:
+
+The recwarn function argument
+------------------------------------
+
+You can use the ``recwarn`` funcarg to assert that code triggers
+warnings through the Python warnings system. Here is a simple
+self-contained test::
+
+ # content of test_recwarn.py
+ 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
+
+The ``recwarn`` function argument provides these methods:
+
+.. method:: pop(category=None)
+
+ Return last warning matching the category.
+
+.. method:: clear()
+
+ Clear list of warnings
+
+
+.. _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``::
+
+ import pytest
+
+ def test_global():
+ pytest.deprecated_call(myfunction, 17)