code: def test_except_hook(wandb_init, test_settings):
      # Test to make sure we respect excepthooks by 3rd parties like pdb
      errs = []
  
      def hook(etype, val, tb):
          return errs.append(str(val))
  
      sys.excepthook = hook
  
      # We cant use raise statement in pytest context
      def raise_(exc):
          return sys.excepthook(type(exc), exc, None)
  
      raise_(Exception("Before wandb.init()"))
  
      run = wandb_init(mode="offline", settings=test_settings())
  
      old_stderr_write = sys.stderr.write
      stderr = []
      sys.stderr.write = stderr.append
  
      raise_(Exception("After wandb.init()"))
  
      assert errs == ["Before wandb.init()", "After wandb.init()"]
  
      # make sure wandb prints the traceback
      assert "".join(stderr) == "Exception: After wandb.init()\n"
  
      sys.stderr.write = old_stderr_write
      run.finish()
  
imports: import json
  import os
  import pickle
  import sys
  import numpy
  import pytest
  import wandb
  from wandb import wandb_sdk
  from wandb.errors import UsageError
label_desc: Use image node_id 11 for calling a global function with example usage: test_except_hook(wandb_init, test_settings) and returns: errs, sys