code: def test_find_tests_customize_via_package_pattern(self):
      # This test uses the example 'do-nothing' load_tests from
      # https://docs.python.org/3/library/unittest.html#load-tests-protocol
      # to make sure that that actually works.
      # Housekeeping
      original_listdir = os.listdir
  
      def restore_listdir():
          os.listdir = original_listdir
  
      self.addCleanup(restore_listdir)
      original_isfile = os.path.isfile
  
      def restore_isfile():
          os.path.isfile = original_isfile
  
      self.addCleanup(restore_isfile)
      original_isdir = os.path.isdir
  
      def restore_isdir():
          os.path.isdir = original_isdir
  
      self.addCleanup(restore_isdir)
      self.addCleanup(sys.path.remove, abspath("/foo"))
  
      # Test data: we expect the following:
      # a listdir to find our package, and isfile and isdir checks on it.
      # a module-from-name call to turn that into a module
      # followed by load_tests.
      # then our load_tests will call discover() which is messy
      # but that finally chains into find_tests again for the child dir -
      # which is why we don't have an infinite loop.
      # We expect to see:
      # the module load tests for both package and plain module called,
      # and the plain module result nested by the package module load_tests
      # indicating that it was processed and could have been mutated.
      vfs = {
          abspath("/foo"): ["my_package"],
          abspath("/foo/my_package"): ["__init__.py", "test_module.py"],
      }
  
      def list_dir(path):
          return list(vfs[path])
  
      os.listdir = list_dir
      os.path.isdir = lambda path: not path.endswith(".py")
      os.path.isfile = lambda path: path.endswith(".py")
  
      class Module(object):
          paths = []
          load_tests_args = []
  
          def __init__(self, path):
              self.path = path
              self.paths.append(path)
              if path.endswith("test_module"):
  
                  def load_tests(loader, tests, pattern):
                      self.load_tests_args.append(
                          (loader, tests, pattern)
                      )
                      return [self.path + " load_tests"]
  
              else:
  
                  def load_tests(loader, tests, pattern):
                      self.load_tests_args.append(
                          (loader, tests, pattern)
                      )
                      # top level directory cached on loader instance
                      __file__ = "/foo/my_package/__init__.py"
                      this_dir = os.path.dirname(__file__)
                      pkg_tests = loader.discover(
                          start_dir=this_dir, pattern=pattern
                      )
                      return [
                          self.path + " load_tests",
                          tests,
                      ] + pkg_tests
  
              self.load_tests = load_tests
  
          def __eq__(self, other):
              return self.path == other.path
  
      loader = unittest.TestLoader()
      loader._get_module_from_name = lambda name: Module(name)
      loader.suiteClass = lambda thing: thing
  
      loader._top_level_dir = abspath("/foo")
      # this time no '.py' on the pattern so that it can match
      # a test package
      suite = list(loader._find_tests(abspath("/foo"), "test*.py"))
  
      # We should have loaded tests from both my_package and
      # my_package.test_module, and also run the load_tests hook in both.
      # (normally this would be nested TestSuites.)
      self.assertEqual(
          suite,
          [
              [
                  "my_package load_tests",
                  [],
                  ["my_package.test_module load_tests"],
              ]
          ],
      )
      # Parents before children.
      self.assertEqual(
          Module.paths, ["my_package", "my_package.test_module"]
      )
  
      # load_tests should have been called twice with loader, tests and pattern
      self.assertEqual(
          Module.load_tests_args,
          [(loader, [], "test*.py"), (loader, [], "test*.py")],
      )
  
imports: import os.path
  from os.path import abspath
  import re
  import sys
  import types
  import pickle
  from test import support
  from test.support import import_helper
  import unittest
  import unittest.mock
  import test.test_unittest
label_desc: Use image node_id 6 for calling the TestDiscovery obj's underlying member method code with example usage: obj.test_find_tests_customize_via_package_pattern() and returns: list, unknown, list, unknown