code: def catch_warnings_for_item(config, ihook, when, item):
      """
      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.
      """
      cmdline_filters = config.getoption("pythonwarnings") or []
      inifilters = config.getini("filterwarnings")
      with warnings.catch_warnings(record=True) as log:
          if not sys.warnoptions:
              # if user is not explicitly configuring warning filters, show deprecation warnings by default (#2908)
              warnings.filterwarnings(
                  "always", category=DeprecationWarning
              )
              warnings.filterwarnings(
                  "always", category=PendingDeprecationWarning
              )
  
          warnings.filterwarnings(
              "error", category=pytest.RemovedInPytest4Warning
          )
  
          # filters should have this precedence: mark, cmdline options, ini
          # filters should be applied in the inverse order of precedence
          for arg in inifilters:
              _setoption(warnings, arg)
  
          for arg in cmdline_filters:
              warnings._setoption(arg)
  
          if item is not None:
              for mark in item.iter_markers(name="filterwarnings"):
                  for arg in mark.args:
                      _setoption(warnings, arg)
  
          yield
  
          for warning_message in log:
              ihook.pytest_warning_captured.call_historic(
                  kwargs=dict(
                      warning_message=warning_message,
                      when=when,
                      item=item,
                  )
              )
  
file_path: catboost/contrib/python/pytest/py2/_pytest/warnings.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import sys
  import warnings
  from contextlib import contextmanager
  import pytest
  from _pytest import compat
label_desc: Use image node_id 4 for calling a global function with example usage: catch_warnings_for_item(config, ihook, when, item) without return types