code: def custom_measurement_process(device, spy):
      assert (
          len(spy.call_args_list) > 0
      )  # make sure method is mocked properly
  
      # pylint: disable=protected-access
      samples = device._samples
      state = flatten_state(device._state, device.num_wires)
      call_args_list = list(spy.call_args_list)
      for call_args in call_args_list:
          obs = call_args.args[1]
          shot_range, bin_size = (
              call_args.kwargs["shot_range"],
              call_args.kwargs["bin_size"],
          )
          meas = qml.var(op=obs)
          old_res = device.var(obs, shot_range, bin_size)
          if samples is not None:
              new_res = meas.process_samples(
                  samples=samples,
                  wire_order=device.wires,
                  shot_range=shot_range,
                  bin_size=bin_size,
              )
          else:
              new_res = meas.process_state(
                  state=state, wire_order=device.wires
              )
          assert qml.math.allclose(old_res, new_res)
  
file_path: pennylane/tests/measurements/legacy/test_var_legacy.py
imports: import numpy
  import pytest
  import pennylane
  from pennylane.measurements import Variance, Shots
  from pennylane.devices.qubit.measure import flatten_state
label_desc: Use image node_id 1 for calling a global function with example usage: custom_measurement_process(device, spy) without return types