def METHOD_NAME(module=None, pytestargs=None):
  '''
  pytest compatibility layer
  This function discovers pytest tests in a module directory so that they can
  be run via libtbx.run_tests_parallel without being named explicitly in the
  module's run_tests.py.
  To use this function, add
    from libtbx.test_utils.pytest import discover
    tst_list = tst_list + discover()
  to your run_tests.py.
  You can pass further arguments to the pytest discovery process as a list in
  the pytestargs parameter, and you can specify the cctbx module name if the
  automatic discovery does not work for any reason.
  The function tests for the presence of pytest and mock, and generates a
  helpful warning if either is missing. You can skip the discovery of tests
  by setting the environment variable LIBTBX_SKIP_PYTEST.
  '''
  if 'LIBTBX_SKIP_PYTEST' in os.environ:
    '''If LIBTBX_SKIP_PYTEST is set then the user is running libtbx testing but
       does not want any pytests to be run.
       Alternatively the user is running pytest, and pytest wants to find all
       legacy libtbx tests. In this case we also do not attempt to recursively
       find pytests.
    '''
    # Buck stops here in either case
    return []
  if pytestargs is None:
    pytestargs = []
  try:
    import pytest
  except ImportError:
    def pytest_warning():
      print("=" * 55)
      print(" WARNING: Skipping some tests for %s\n" % module)
      print(" To run all available tests you need to install pytest.")
      print("    libtbx.python -m pip install pytest")
      print("=" * 55)
    pytest_warning()
    atexit.register(pytest_warning)
    return []
  if not module:
    # Try to determine the name of the calling module, and thus the name of the
    # cctbx module. Use exception trick to pick up the current frame.
    try:
      raise Exception()
    except Exception:
      frame = sys.exc_info()[2].tb_frame.f_back
    caller = frame.f_globals['__name__']
    if not caller.endswith('.run_tests'):
      raise RuntimeError('Only use discover() from within run_tests.py ' \
                       + 'or specify the module name manually.')
    module = caller[:-10]
  class L(list):
    """Subclass list so that it can accept additional attributes."""
  print("Discovering pytest tests for %s:" % module)
  test_list = []
  dist_dir = libtbx.env.dist_path(module)
  class TestDiscoveryPlugin:
    def pytest_itemcollected(self, item):
      global _pytest_unique_counter
      testarray = L([ "libtbx.python", "-m", "pytest", '-rsxX', '--basetemp=pytest%st%03d' % (os.path.sep, next(_pytest_unique_counter)),
        '"%s"' % (item.fspath + '::' + item.nodeid.split('::', 1)[1]) ])
      testclass = module + '.' + item.location[0].replace(os.path.sep, '.')
      if testclass.endswith('.py'):
        testclass = testclass[:-3]
      testarray.test_class = testclass
      testarray.test_name = item.name
      test_list.append(testarray)
  pytest_parameters = ['-qq', '--collect-only']
  # Only show pytest warnings during first collection
  global _first_pytest_collection
  if not _first_pytest_collection:
    pytest_parameters.append('--disable-pytest-warnings')
  _first_pytest_collection = False
  try:
    # Now set LIBTBX_SKIP_PYTEST so we can collect all pytests without pytest
    # recursively trying to find legacy libtbx tests.
    os.environ['LIBTBX_SKIP_PYTEST'] = "1"
    pytest.main(pytest_parameters + [ dist_dir ] + pytestargs, plugins=[TestDiscoveryPlugin()])
  finally:
    del os.environ['LIBTBX_SKIP_PYTEST']
  if test_list:
    # Ensure the common basetemp directory pytest/ exists
    try:
      os.mkdir('pytest')
    except OSError:
      pass
  return test_list