code: def test_output(self, tmpdir):
      # first, make expected gradients to temp directory
      expected_result_path = str(tmpdir)
  
      model = self.get_model()
      x = input_generator.increasing(2, 5)
      export_testcase(model, x, expected_result_path, output_grad=True)
  
      data_set_name = "test_data_set_0"
      expected_gradients = [
          os.path.join(
              expected_result_path, data_set_name, "gradient_{}.pb"
          ).format(i)
          for i in range(2)
      ]
      assert all([os.path.isfile(path) for path in expected_gradients])
  
      # model.half returns chainer.Variable and enabled backward
      # regardless using replacing
      model.half = fake_as_funcnode(model.half, "MulConstant")
      x = input_generator.increasing(2, 5)
  
      def gradient_check(model, path):
          actual_gradients = [
              os.path.join(
                  path, data_set_name, "gradient_{}.pb"
              ).format(i)
              for i in range(2)
          ]
          assert all(
              [os.path.isfile(path) for path in actual_gradients]
          )
  
          def load_tensor(path):
              tensor = onnx.load_tensor(path)
              return onnx.numpy_helper.to_array(tensor)
  
          for e_path, a_path in zip(
              expected_gradients, actual_gradients
          ):
              expected = load_tensor(e_path)
              actual = load_tensor(a_path)
              np.testing.assert_allclose(expected, actual)
  
      self.expect(
          model,
          x,
          output_grad=True,
          custom_model_test_func=gradient_check,
      )
  
imports: import os
  import warnings
  import chainer
  import chainer.functions
  import chainer.links
  from chainer import testing
  import numpy
  import onnx
  import pytest
  from onnx_chainer import export
  from onnx_chainer import export_testcase
  from onnx_chainer import onnx_helper
  from onnx_chainer.replace_func import as_funcnode
  from onnx_chainer.replace_func import fake_as_funcnode
  from onnx_chainer.testing import input_generator
  from onnx_chainer_tests.helper import ONNXModelChecker
  from onnx_chainer_tests.helper import ONNXModelTest
label_desc: Use image node_id 3 for calling the TestReplaceWithOutputGrad obj's underlying member method code with example usage: obj.test_output(tmpdir) and returns: onnx