def setUp(self):
    super(GRRBaseTest, self).setUp()

    tmpdir = os.environ.get("TEST_TMPDIR") or config_lib.CONFIG["Test.tmpdir"]

    # Make a temporary directory for test files.
    self.temp_dir = tempfile.mkdtemp(dir=tmpdir)

    config_lib.CONFIG.SetWriteBack(
        os.path.join(self.temp_dir, "writeback.yaml"))

    if self.install_mock_acl:
      # Enforce checking that security tokens are propagated to the data store
      # but no actual ACLs.
      data_store.DB.security_manager = MockSecurityManager()

    logging.info("Starting test: %s.%s",
                 self.__class__.__name__, self._testMethodName)
    self.last_start_time = time.time()

    try:
      # Clear() is much faster than init but only supported for FakeDataStore.
      data_store.DB.Clear()
    except __HOLE__:
      self.InitDatastore()

    aff4.FACTORY.Flush()

    # Create a Foreman and Filestores, they are used in many tests.
    aff4_grr.GRRAFF4Init().Run()
    filestore.FileStoreInit().Run()
    hunts_results.ResultQueueInitHook().Run()
    api_auth_manager.APIACLInit.InitApiAuthManager()

    # Stub out the email function
    self.emails_sent = []

    def SendEmailStub(to_user, from_user, subject, message, **unused_kwargs):
      self.emails_sent.append((to_user, from_user, subject, message))

    self.mail_stubber = utils.MultiStubber(
        (email_alerts.EMAIL_ALERTER, "SendEmail", SendEmailStub),
        (email.utils, "make_msgid", lambda: "<message id stub>"))
    self.mail_stubber.Start()

    self.nanny_stubber = utils.Stubber(
        client_utils_linux.NannyController, "StartNanny",
        lambda unresponsive_kill_period=None, nanny_logfile=None: True)
    self.nanny_stubber.Start()
dataset/ETHPy150Open google/grr/grr/lib/test_lib.py/GRRBaseTest.setUp