code: def test_set_nomemory(self):
      code = """if 1:
              import _testcapi
  
              class C(): pass
  
              # The first loop tests both functions and that remove_mem_hooks()
              # can be called twice in a row. The second loop checks a call to
              # set_nomemory() after a call to remove_mem_hooks(). The third
              # loop checks the start and stop arguments of set_nomemory().
              for outer_cnt in range(1, 4):
                  start = 10 * outer_cnt
                  for j in range(100):
                      if j == 0:
                          if outer_cnt != 3:
                              _testcapi.set_nomemory(start)
                          else:
                              _testcapi.set_nomemory(start, start + 1)
                      try:
                          C()
                      except MemoryError as e:
                          if outer_cnt != 3:
                              _testcapi.remove_mem_hooks()
                          print('MemoryError', outer_cnt, j)
                          _testcapi.remove_mem_hooks()
                          break
          """
      rc, out, err = assert_python_ok("-c", code)
      lines = out.splitlines()
      for i, line in enumerate(lines, 1):
          self.assertIn(b"MemoryError", out)
          *_, count = line.split(b" ")
          count = int(count)
          self.assertLessEqual(count, i * 5)
          self.assertGreaterEqual(count, i * 5 - 2)
  
imports: import re
  import textwrap
  import unittest
  from test import support
  from test.support import import_helper, requires_subprocess
  from test.support.script_helper import assert_python_failure, assert_python_ok
label_desc: Use image node_id 12 for calling the PyMemDebugTests obj's underlying member method code with example usage: obj.test_set_nomemory() without return types