docstr: As a context manager, test if wrapped code raises any warning with
   message that contains the regex pattern :attr:`regex`.
docstr_tok: ["As","a","context","manager",",","test","if","wrapped","code","raises","any","warning","with","message","that","contains","the","regex","pattern",":","attr",":","`","regex","`","."]
code: def assertWarnsRegex(self, regex, msg=""):
      r"""
      As a context manager, test if wrapped code raises any warning with
       message that contains the regex pattern :attr:`regex`.
      """
      with warnings.catch_warnings(record=True) as ws:
          warnings.simplefilter(
              "always"
          )  # allow any warning to be raised
          yield
          self.assertTrue(len(ws) > 0, msg)
          found = any(
              re.search(regex, str(w.message)) is not None for w in ws
          )
          self.assertTrue(found, msg)
  
imports: import contextlib
  import functools
  import re
  import warnings
  from unittest import TestCase
  import torch
  from pytext.optimizer import Lamb, StochasticWeightAveraging
  from torch import nn, optim, sparse
  from torch.autograd import Variable
  from torch.utils import data
label_desc: Use image node_id 1 for calling the TestSWA obj's underlying member method code with example usage: obj.assertWarnsRegex(regex, msg) without return types