.. 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)