@contextmanager<EOL>def catch_warnings_for_item(config, ihook, when, item):
cmdline_filters = config.getoption("<STR_LIT>") or []<EOL>inifilters = config.getini("<STR_LIT>")<EOL>with warnings.catch_warnings(record=True) as log:<EOL><INDENT>if not sys.warnoptions:<EOL><INDENT>warnings.filterwarnings("<STR_LIT>", category=DeprecationWarning)<EOL>warnings.filterwarnings("<STR_LIT>", category=PendingDeprecationWarning)<EOL><DEDENT>warnings.filterwarnings("<STR_LIT:error>", category=pytest.RemovedInPytest4Warning)<EOL>for arg in inifilters:<EOL><INDENT>_setoption(warnings, arg)<EOL><DEDENT>for arg in cmdline_filters:<EOL><INDENT>warnings._setoption(arg)<EOL><DEDENT>if item is not None:<EOL><INDENT>for mark in item.iter_markers(name="<STR_LIT>"):<EOL><INDENT>for arg in mark.args:<EOL><INDENT>_setoption(warnings, arg)<EOL><DEDENT><DEDENT><DEDENT>yield<EOL>for warning_message in log:<EOL><INDENT>ihook.pytest_warning_captured.call_historic(<EOL>kwargs=dict(warning_message=warning_message, when=when, item=item)<EOL>)<EOL><DEDENT><DEDENT>
Context manager that catches warnings generated in the contained execution block.

``item`` can be None if we are not in the context of an item execution.

Each warning captured triggers the ``pytest_warning_captured`` hook.