Skip to main content

pytest plugin to run the tests with support of pyspark.

Project description

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.

Install

$ pip install pytest-spark

Usage

Set Spark location

To run tests with required spark_home location you need to define it by using one of the following methods:

  1. Specify command line option “–spark_home”:

    $ pytest --spark_home=/opt/spark
  2. Add “spark_home” value to pytest.ini in your project directory:

    [pytest]
    spark_home = /opt/spark
  3. Set the “SPARK_HOME” environment variable.

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

Using the spark_context 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.

Example:

def test_my_case(spark_context):
    test_rdd = spark_context.parallelize([1, 2, 3, 4])
    # ...

Using the spark_session fixture (Spark 2.0 and above)

Use fixture spark_session in your tests as a regular pyspark fixture. A SparkSession instance with Hive support enabled will be created once and reused for the whole test session.

Example:

def test_spark_session_dataframe(spark_session):
    test_df = spark_session.createDataFrame([[1,3],[2,4]], "a: int, b: int")
    # ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-spark-0.4.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytest_spark-0.4.5-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-spark-0.4.5.tar.gz.

File metadata

  • Download URL: pytest-spark-0.4.5.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for pytest-spark-0.4.5.tar.gz
Algorithm Hash digest
SHA256 77125b80d6be318c1081a12a074e2d76955c08241fc5a2fb437779b1f5ad826e
MD5 a54bb1f9d11ff6227d348ffd7c7cb50a
BLAKE2b-256 0a304b1a082dfb6db4ceff3be9a45eefb1f59082c2c97410248d9b7c49309036

See more details on using hashes here.

File details

Details for the file pytest_spark-0.4.5-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_spark-0.4.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for pytest_spark-0.4.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4d924894cb36e45a69031ff4e2f1c025ba744677fe5f2e40bac308c01dfaf566
MD5 26394c7fed08c480d410775ccdf9fe71
BLAKE2b-256 6485d284c10f5beeb5b2099d047c55127322e7db9cb18eab550f164c23b94234

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page