class_docstr: Tests for the var function
class_docstr_tok: ["Tests","for","the","var","function"]
docstr: Tests that the variance of a ``Projector`` object is computed correctly.
docstr_tok: ["Tests","that","the","variance","of","a","``","Projector","``","object","is","computed","correctly","."]
code: def test_projector_var(self, state, shots, mocker):
      """Tests that the variance of a ``Projector`` object is computed correctly."""
      dev = qml.device("default.qubit.legacy", wires=3, shots=shots)
      spy = mocker.spy(qml.QubitDevice, "var")
  
      @qml.qnode(dev)
      def circuit():
          qml.Hadamard(0)
          return qml.var(qml.Projector(state, wires=range(3)))
  
      res = circuit()
      expected = [0.25, 0.25] if isinstance(shots, list) else 0.25
  
      assert np.allclose(res, expected, atol=0.02, rtol=0.02)
  
      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 8 for calling the TestVar obj's underlying member method code with example usage: obj.test_projector_var(state, shots, mocker) and returns: qml