code: def test_wrap_session_notify_exception(
      ret_exc, pytester: Pytester
  ) -> None:
      returncode, exc = ret_exc
      c1 = pytester.makeconftest(
          """
          import pytest
  
          def pytest_sessionstart():
              raise {exc}("boom")
  
          def pytest_internalerror(excrepr, excinfo):
              returncode = {returncode!r}
              if returncode is not False:
                  pytest.exit("exiting after %s..." % excinfo.typename, returncode={returncode!r})
      """.format(
              returncode=returncode, exc=exc.__name__
          )
      )
      result = pytester.runpytest()
      if returncode:
          assert result.ret == returncode
      else:
          assert result.ret == ExitCode.INTERNAL_ERROR
      assert (
          result.stdout.lines[0]
          == "INTERNALERROR> Traceback (most recent call last):"
      )
  
      end_lines = (
          result.stdout.lines[-4:]
          if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
          else result.stdout.lines[-3:]
      )
  
      if exc == SystemExit:
          assert end_lines == [
              f'INTERNALERROR>   File "{c1}", line 4, in pytest_sessionstart',
              'INTERNALERROR>     raise SystemExit("boom")',
              *(
                  ("INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^",)
                  if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
                  else ()
              ),
              "INTERNALERROR> SystemExit: boom",
          ]
      else:
          assert end_lines == [
              f'INTERNALERROR>   File "{c1}", line 4, in pytest_sessionstart',
              'INTERNALERROR>     raise ValueError("boom")',
              *(
                  ("INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^",)
                  if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
                  else ()
              ),
              "INTERNALERROR> ValueError: boom",
          ]
      if returncode is False:
          assert result.stderr.lines == [
              "mainloop: caught unexpected SystemExit!"
          ]
      else:
          assert result.stderr.lines == [
              f"Exit: exiting after {exc.__name__}..."
          ]
  
imports: import argparse
  import os
  import re
  import sys
  from pathlib import Path
  from typing import Optional
  import pytest
  from _pytest.config import ExitCode
  from _pytest.config import UsageError
  from _pytest.main import resolve_collection_argument
  from _pytest.main import validate_basetemp
  from _pytest.pytester import Pytester
label_desc: Use image node_id 1 for calling a global function with example usage: test_wrap_session_notify_exception(ret_exc, pytester) without return types