code: def test_if_sheet_exists_raises(ext, if_sheet_exists, msg):
      # GH 40230
      df = DataFrame({"fruit": ["pear"]})
      with tm.ensure_clean(ext) as f:
          df.to_excel(f, sheet_name="foo", engine="openpyxl")
          with pytest.raises(ValueError, match=re.escape(msg)):
              with ExcelWriter(
                  f,
                  engine="openpyxl",
                  mode="a",
                  if_sheet_exists=if_sheet_exists,
              ) as writer:
                  df.to_excel(writer, sheet_name="foo")
  
imports: import contextlib
  from pathlib import Path
  import re
  import numpy
  import pytest
  import pandas
  from pandas import DataFrame
  import pandas._testing
  from pandas.io.excel import ExcelWriter, _OpenpyxlWriter
  from pandas.io.excel._openpyxl import OpenpyxlReader
label_desc: Use image node_id 11 for calling a global function with example usage: test_if_sheet_exists_raises(ext, if_sheet_exists, msg) without return types