class_docstr: Test cases for diagnostics emitted by the TorchScript ONNX export code.
class_docstr_tok: ["Test","cases","for","diagnostics","emitted","by","the","TorchScript","ONNX","export","code","."]
code: def test_py_diagnose_emits_error(self):
      class M(torch.nn.Module):
          def forward(self, x):
              return torch.diagonal(x)
  
      with assert_diagnostic(
          self,
          diagnostics.engine,
          diagnostics.rules.operator_supported_in_newer_opset_version,
          diagnostics.levels.ERROR,
      ):
          # trigger error for operator unsupported until newer opset version.
          torch.onnx.export(
              M(),
              torch.randn(3, 4),
              io.BytesIO(),
              opset_version=9,
          )
  
imports: from __future__ import annotations
  import contextlib
  import dataclasses
  import io
  import logging
  import typing
  import unittest
  from typing import AbstractSet, Protocol, Tuple
  import torch
  from torch.onnx import errors
  from torch.onnx._internal import diagnostics
  from torch.onnx._internal.diagnostics import infra
  from torch.onnx._internal.diagnostics.infra import formatter, sarif
  from torch.onnx._internal.fx import diagnostics
  from torch.testing._internal import common_utils, logging_utils
label_desc: Use image node_id 5 for calling the TestTorchScriptOnnxDiagnostics obj's underlying member method code with example usage: obj.test_py_diagnose_emits_error() and returns: torch