skip to navigation
skip to content

pytest-spark 0.2.0

pytest plugin to run the tests with support of pyspark.

pytest plugin to run the tests with support of pyspark (Apache Spark).

This plugin will allow to specify SPARK_HOME directory in pytest.ini and thus to make “pyspark” importable in your tests which are executed by pytest.

Also it defines session scope fixture spark_context which can be used in your tests.


$ pip install pytest-spark


Set Spark location

To run tests with required spark_home location just add “spark_home” value to pytest.ini in your project directory:

spark_home = /opt/spark

pytest-spark will try to import pyspark from specified location.

Using fixture

Use fixture spark_context in your tests as a regular pyspark fixture. SparkContext instance will be created once and reused for the whole test session.


def test_my_case(spark_context):
    test_rdd = spark_context.parallelize([1, 2, 3, 4])
    # ...
File Type Py Version Uploaded on Size
pytest-spark-0.2.0.tar.gz (md5) Source 2017-02-22 2KB
pytest_spark-0.2.0-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2017-02-22 4KB