public String cliInit() throws Exception {
    File file = Objects.requireNonNull(inputFile);
    String fileName = inputFile.getName();

    dispatcher.process(file);
    dispatcher.beforeTest(this);

    if (!qTestResultProcessor.canReuseSession()) {
      newSession(false);
    }

    CliSessionState ss = (CliSessionState) SessionState.get();

    String outFileExtension = getOutFileExtension();
    String stdoutName = null;

    if (outDir != null) {
      // TODO: why is this needed?
      File qf = new File(outDir, fileName);
      stdoutName = qf.getName().concat(outFileExtension);
    } else {
      stdoutName = fileName + outFileExtension;
    }
    File outf = new File(logDir, stdoutName);
    setSessionOutputs(ss, outf);
    ss.setIsQtestLogging(true);

    if (fileName.equals("init_file.q")) {
      ss.initFiles.add(AbstractCliConfig.HIVE_ROOT + "/data/scripts/test_init_file.sql");
    }
    cliDriver.processInitFiles(ss);

    return outf.getAbsolutePath();
  }
Clear out any side effects of running tests
itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java