code: def spark(
      tmp_path_factory, app_name="Sample", url="local[*]", memory="1G"
  ):
      """Start Spark if not started
      Args:
          app_name (str): sets name of the application
          url (str): url for spark master
          memory (str): size of memory for spark driver
      """
  
      try:
          sarplus_jar_path = next(
              Path(__file__)
              .parents[2]
              .joinpath("scala", "target")
              .glob("**/sarplus*.jar")
          ).absolute()
      except StopIteration:
          raise Exception("Could not find Sarplus JAR file")
  
      spark = (
          SparkSession.builder.appName(app_name)
          .master(url)
          .config("spark.jars", sarplus_jar_path)
          .config("spark.driver.memory", memory)
          .config("spark.sql.shuffle.partitions", "1")
          .config("spark.default.parallelism", "1")
          .config("spark.sql.crossJoin.enabled", True)
          .config("spark.ui.enabled", False)
          .config(
              "spark.sql.warehouse.dir",
              str(tmp_path_factory.mktemp("spark")),
          )
          # .config("spark.eventLog.enabled", True) # only for local debugging, breaks on build server
          .getOrCreate()
      )
  
      return spark
  
imports: import math
  from pathlib import Path
  import numpy
  import pandas
  from pyspark.sql import SparkSession
  import pytest
  from pandas.testing import assert_frame_equal
  from pysarplus import SARPlus, SARModel
label_desc: Use image node_id 2 for calling a global function with example usage: spark(tmp_path_factory, app_name, url, memory) and returns: spark