code: def __exit__(
      self,
      exc_type: Optional[Type[BaseException]],
      exc_val: Optional[BaseException],
      exc_tb: Optional[TracebackType],
  ) -> None:
      super().__exit__(exc_type, exc_val, exc_tb)
  
      __tracebackhide__ = True
  
      def found_str():
          return pformat([record.message for record in self], indent=2)
  
      # only check if we're not currently handling an exception
      if exc_type is None and exc_val is None and exc_tb is None:
          if self.expected_warning is not None:
              if not any(
                  issubclass(r.category, self.expected_warning)
                  for r in self
              ):
                  __tracebackhide__ = True
                  fail(
                      f"DID NOT WARN. No warnings of type {self.expected_warning} were emitted.\n"
                      f"The list of emitted warnings is: {found_str()}."
                  )
              elif self.match_expr is not None:
                  for r in self:
                      if issubclass(r.category, self.expected_warning):
                          if re.compile(self.match_expr).search(
                              str(r.message)
                          ):
                              break
                  else:
                      fail(
                          f"""\
  DID NOT WARN. No warnings of type {self.expected_warning} matching the regex were emitted.
   Regex: {self.match_expr}
   Emitted warnings: {found_str()}"""
                      )
  
imports: import re
  import warnings
  from pprint import pformat
  from types import TracebackType
  from typing import Any
  from typing import Callable
  from typing import Generator
  from typing import Iterator
  from typing import List
  from typing import Optional
  from typing import Pattern
  from typing import Tuple
  from typing import Type
  from typing import TypeVar
  from typing import Union
  from _pytest.compat import final
  from _pytest.compat import overload
  from _pytest.deprecated import check_ispytest
  from _pytest.deprecated import WARNS_NONE_ARG
  from _pytest.fixtures import fixture
  from _pytest.outcomes import fail
label_desc: Use image node_id 2 for calling the WarningsChecker obj's underlying member method code with example usage: obj.__exit__(exc_type, exc_val, exc_tb) and returns: pformat