class_docstr: Dependency management API tests.
  - mock()
  - extern()
  - deny()
class_docstr_tok: ["Dependency","management","API","tests",".","-","mock","(",")","-","extern","(",")","-","deny","(",")"]
docstr: If an error occurs during packaging, it should not be shadowed by the allow_empty error.
docstr_tok: ["If","an","error","occurs","during","packaging",",","it","should","not","be","shadowed","by","the","allow_empty","error","."]
code: def test_allow_empty_with_error(self):
      """If an error occurs during packaging, it should not be shadowed by the allow_empty error."""
      buffer = BytesIO()
      with self.assertRaises(ModuleNotFoundError):
          with PackageExporter(buffer) as pe:
              # Even though we did not extern a module that matches this
              # pattern, we want to show the save_module error, not the allow_empty error.
  
              pe.extern("foo", allow_empty=False)
              pe.save_module("aodoifjodisfj")  # will error
  
              # we never get here, so technically the allow_empty check
              # should raise an error. However, the error above is more
              # informative to what's actually going wrong with packaging.
              pe.save_source_string("bar", "import foo\n")
  
imports: import importlib
  from io import BytesIO
  from sys import version_info
  from textwrap import dedent
  from unittest import skipIf
  import torch.nn
  from torch.package import EmptyMatchError, Importer, PackageExporter, PackageImporter
  from torch.package.package_exporter import PackagingError
  from torch.testing._internal.common_utils import IS_WINDOWS, run_tests
label_desc: Use image node_id 11 for calling the TestDependencyAPI obj's underlying member method code with example usage: obj.test_allow_empty_with_error() without return types