Skip to content

Instantly share code, notes, and snippets.

@mamonu
Created October 29, 2018 15:15
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 mamonu/ba1a1010df49f686457ae11ec437cf15 to your computer and use it in GitHub Desktop.
Save mamonu/ba1a1010df49f686457ae11ec437cf15 to your computer and use it in GitHub Desktop.
pyspark fixture example
@pytest.fixture(scope="session")
def spark_context(request):
""" fixture for creating a spark context
Args:
request: pytest.FixtureRequest object
"""
conf = (SparkConf().setMaster("local[2]").setAppName("pytest-pyspark-local-testing"))
sc = SparkContext(conf=conf)
request.addfinalizer(lambda: sc.stop())
quiet_py4j()
return sc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment