cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to pass a Spark session to other python files?

tomcorbin
New Contributor III

I am setting up pytest for my repo. I have my functions in separate python files and run pytest from one notebook. For each testing file, I have to create a new Spark session as follows:

@pytest.fixture(scope="session")
def spark():
  spark = (
  SparkSession.builder.master("local[1]")
  .appName("test")
  .config("spark.executors.cores", "1")
  .config("spark.executors.instances", "1")
  .config("spark.sql.shuffle.partitions", "1")
  .getOrCreate()
  )
  yield spark
  spark.stop()
 
Is it possible to create one Spark session and pass it to the test files that need it?
1 ACCEPTED SOLUTION

Accepted Solutions

tomcorbin
New Contributor III

I was able to do it by placing the Spark session fixture in the conftest.py file in the root directory. 

View solution in original post

1 REPLY 1

tomcorbin
New Contributor III

I was able to do it by placing the Spark session fixture in the conftest.py file in the root directory. 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group