class_docstr: Tests for the var function
class_docstr_tok: ["Tests","for","the","var","function"]
docstr: Test that the var function works
docstr_tok: ["Test","that","the","var","function","works"]
code: def test_value(self, tol, r_dtype, mocker, shots):
      """Test that the var function works"""
      dev = qml.device("default.qubit.legacy", wires=2, shots=shots)
      spy = mocker.spy(qml.QubitDevice, "var")
      dev.R_DTYPE = r_dtype
  
      @qml.qnode(dev, diff_method="parameter-shift")
      def circuit(x):
          qml.RX(x, wires=0)
          return qml.var(qml.PauliZ(0))
  
      x = 0.54
      res = circuit(x)
      expected = (
          [np.sin(x) ** 2, np.sin(x) ** 2]
          if isinstance(shots, list)
          else np.sin(x) ** 2
      )
      atol = tol if shots is None else 0.05
      rtol = 0 if shots is None else 0.05
  
      assert np.allclose(res, expected, atol=atol, rtol=rtol)
      # pylint: disable=no-member, unsubscriptable-object
      if isinstance(res, tuple):
          assert res[0].dtype == r_dtype
          assert res[1].dtype == r_dtype
      else:
          assert res.dtype == r_dtype
  
      custom_measurement_process(dev, spy)
  
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 the TestVar obj's underlying member method code with example usage: obj.test_value(tol, r_dtype, mocker, shots) and returns: qml