code: def format_test_output(test_name, test_res, H0_unit_root=True):
      """
      Helper function to format output. Return a dictionary with specific keys. Will be used to
      construct the summary data frame for all unit root tests.
  
      TODO: Add functionality of choosing based on the max lag order specified by user.
  
      :param test_name: name of the test
      :param test_res: object that contains corresponding test information. Can be None if test failed.
      :param H0_unit_root: does the null hypothesis of the test assume a unit root process? Some tests do (ADF),
                           some don't (KPSS).
      :return: dictionary of summary table for all tests and final decision on stationary vs non-stationary.
               If test failed (test_res is None), return empty dictionary.
      """
      # Check if the test failed by trying to extract the test statistic
      if test_name in ("ADF", "KPSS"):
          try:
              test_res["statistic"]
          except BaseException:
              test_res = None
      else:
          try:
              test_res.stat
          except BaseException:
              test_res = None
  
      if test_res is None:
          return {}
  
      # extract necessary information
      if test_name in ("ADF", "KPSS"):
          statistic = test_res["statistic"]
          crit_val = test_res["critical"]["5%"]
          p_val = test_res["pval"]
          lags = (
              test_res["resstore"].usedlag
              if test_name == "ADF"
              else test_res["lags"]
          )
      else:
          statistic = test_res.stat
          crit_val = test_res.critical_values["5%"]
          p_val = test_res.pvalue
          lags = test_res.lags
  
      if H0_unit_root:
          H0 = "The process is non-stationary"
          stationary = "yes" if p_val < 0.05 else "not"
      else:
          H0 = "The process is stationary"
          stationary = "yes" if p_val > 0.05 else "not"
  
      out = {
          "test_name": test_name,
          "statistic": statistic,
          "crit_val": crit_val,
          "p_val": p_val,
          "lags": int(lags),
          "stationary": stationary,
          "Null Hypothesis": H0,
      }
      return out
  
file_path: MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/helper_functions.py
imports: import pandas
  import statsmodels.tsa.stattools
  from arch import unitroot
  from azureml.automl.core.shared import constants
  from azureml.automl.runtime.shared.score import scoring
label_desc: Use image node_id 3 for calling a global function with example usage: format_test_output(test_name, test_res, H0_unit_root) and returns: out, dict