I have this function:
# spark already defined somewhere as:
spark = SparkSession.builder.appName("App").getOrCreate()
def read_data(spark):
query = "SELECT * FROM table"
pandas_df = pd.read_sql(query, conn)
return spark.createDataFrame(pandas_df)
To test it:
from unittest import mock
@mock.patch("pandas.read_sql")
@mock.patch("pyspark.sql.SparkSession", autospec=True)
def test_read_data(spark_session, pandas_read_sql):
result = read_data(spark_session)
assert == ???
In what way should I test this that makes sense? Any help appreciated.