docstr: Ensure pytest.raises does not leave a reference cycle (#1965).
docstr_tok: ["Ensure","pytest.raises","does","not","leave","a","reference","cycle","(","#","1965",")","."]
code: def test_raises_cyclic_reference(self, method):
      """Ensure pytest.raises does not leave a reference cycle (#1965)."""
      import gc
  
      class T:
          def __call__(self):
              raise ValueError
  
      t = T()
      refcount = len(gc.get_referrers(t))
  
      if method == "function":
          pytest.raises(ValueError, t)
      elif method == "function_match":
          pytest.raises(ValueError, t).match("^$")
      else:
          with pytest.raises(ValueError):
              t()
  
      # ensure both forms of pytest.raises don't leave exceptions in sys.exc_info()
      assert sys.exc_info() == (None, None, None)
  
      assert refcount == len(gc.get_referrers(t))
  
imports: import re
  import sys
  import pytest
  from _pytest.outcomes import Failed
  from _pytest.pytester import Pytester
label_desc: Use image node_id 16 for calling the TestRaises obj's underlying member method code with example usage: obj.test_raises_cyclic_reference(method) without return types