code: def test_bytesio():
      """Verify that writing to a BytesIO object contains the same data as to_image().
  
      The goal of this test is to ensure that Plotly correctly handles a writable buffer
      which doesn't correspond to a filesystem path.
      """
      bio = BytesIO()
      pio.write_image(
          fig, bio, format="jpg", engine="kaleido", validate=False
      )
      bio.seek(
          0
      )  # Rewind to the beginning of the buffer, otherwise read() returns b''.
      bio_bytes = bio.read()
      to_image_bytes = pio.to_image(
          fig, format="jpg", engine="kaleido", validate=False
      )
      assert bio_bytes == to_image_bytes
  
file_path: plotly.py/packages/python/plotly/plotly/tests/test_optional/test_kaleido/test_kaleido.py
imports: import plotly.io
  import plotly.io.kaleido
  from contextlib import contextmanager
  from io import BytesIO
  from pathlib import Path
  from unittest.mock import Mock
label_desc: Use image node_id 10 for calling a global function with example usage: test_bytesio() without return types