docstr: Test PyErr_Format()
docstr_tok: ["Test","PyErr_Format","(",")"]
code: def test_format(self):
      """Test PyErr_Format()"""
      import_helper.import_module("ctypes")
      from ctypes import pythonapi, py_object, c_char_p, c_int
  
      name = "PyErr_Format"
      PyErr_Format = getattr(pythonapi, name)
      PyErr_Format.argtypes = (
          py_object,
          c_char_p,
      )
      PyErr_Format.restype = py_object
      with self.assertRaises(ZeroDivisionError) as e:
          PyErr_Format(ZeroDivisionError, b"%s %d", b"error", c_int(42))
      self.assertEqual(e.exception.args, ("error 42",))
      with self.assertRaises(ZeroDivisionError) as e:
          PyErr_Format(ZeroDivisionError, b"%s", "помилка".encode())
      self.assertEqual(e.exception.args, ("помилка",))
  
      with self.assertRaisesRegex(OverflowError, "not in range"):
          PyErr_Format(ZeroDivisionError, b"%c", c_int(-1))
      with self.assertRaisesRegex(ValueError, "format string"):
          PyErr_Format(ZeroDivisionError, b"\xff")
      self.assertRaises(SystemError, PyErr_Format, list, b"error")
  
imports: import errno
  import os
  import re
  import sys
  import unittest
  from test import support
  from test.support import import_helper
  from test.support.os_helper import TESTFN, TESTFN_UNDECODABLE
  from test.support.script_helper import assert_python_failure
  from test.support.testcase import ExceptionIsLikeMixin
  from .test_misc import decode_stderr
label_desc: Use image node_id 6 for calling the Test_ErrSetAndRestore obj's underlying member method code with example usage: obj.test_format() without return types