Skip to content

Instantly share code, notes, and snippets.

@priyanlc
Created May 10, 2020 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyanlc/b4367b66a8eadafeff1fe89ba9aa9657 to your computer and use it in GitHub Desktop.
Save priyanlc/b4367b66a8eadafeff1fe89ba9aa9657 to your computer and use it in GitHub Desktop.
# conftest.py
import pytest
from pyspark import SparkConf
from pyspark.sql import SparkSession
@pytest.fixture(scope="session")
def spark():
"""
Fixture for Spark Sessions.
we use the name `spark`, as that is is the same name you can
expect for the automatically injected session you find in pyspark
shells or pysparb Databricks notebooks.
"""
# Setup
spark_session = SparkSession.builder.config(conf=conf).getOrCreate()
yield spark_session
# Teardown
spark_session.stop()
conf = (
SparkConf()
.setMaster("local")
.setAppName("testing")
.set("spark.driver.host", "localhost")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment