test_ok2/doc/ja/recwarn.txt

63 lines
1.9 KiB
Plaintext
Raw Normal View History

..
Asserting deprecation and other warnings
=====================================================
非推奨の警告やその他の警告のアサート
====================================
..
The recwarn function argument
------------------------------------
関数の引数 recwarn
------------------
..
You can use the ``recwarn`` funcarg to assert that code triggers
warnings through the Python warnings system. Here is a simple
self-contained test::
Python のワーニングシステムからの警告を受け取るコードをアサートするために ``recwarn`` という関数の引数が使えます。簡単な自己完結型のテストを紹介します::
# 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:
関数の引数 ``recwarn`` は次のメソッドを提供します:
..
* ``pop(category=None)``: return last warning matching the category.
* ``clear()``: clear list of warnings
* ``pop(category=None)``: カテゴリに一致する最後の警告を返す
* ``clear()``: 警告の一覧をクリアする
..
Ensuring a function triggers a deprecation warning
-------------------------------------------------------
非推奨の警告を発生させる関数の確認
----------------------------------
..
You can also call a global helper for checking
that a certain function call triggers a Deprecation
warning::
非推奨の警告を発生させる特定の関数呼び出しを確認するためのグローバルなヘルパー関数も呼び出せます::
import pytest
def test_global():
pytest.deprecated_call(myfunction, 17)