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.
You can also define “spark_options” in pytest.ini to customize pyspark, including “spark.jars.packages” option which allows to load external libraries (e.g. “com.databricks:spark-xml”).
pytest-spark provides session scope fixtures spark_context and spark_session 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:
Specify command line option “–spark_home”:
$ pytest --spark_home=/opt/spark
Add “spark_home” value to pytest.ini in your project directory:
[pytest] spark_home = /opt/spark
Set the “SPARK_HOME” environment variable.
pytest-spark will try to import pyspark from provided location.
Customize spark_options
Just define “spark_options” in your pytest.ini, e.g.:
[pytest] spark_home = /opt/spark spark_options = spark.app.name: my-pytest-spark-tests spark.executor.instances: 1 spark.jars.packages: com.databricks:spark-xml_2.12:0.5.0
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-spark-0.5.1.tar.gz
.
File metadata
- Download URL: pytest-spark-0.5.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5165f572dce8dea8afd00cd2dc22d9ec6a0399f7bbab6b9e76ec4a1f4da69999 |
|
MD5 | 889fe928639b936a40246d5ec6b25550 |
|
BLAKE2b-256 | 9e70484d03ee629eee8201c219291a888576b48fe8c2f26ae92f687b2a4a6c81 |
File details
Details for the file pytest_spark-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_spark-0.5.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e2f1ac4d839c355540661ebcca15f86375a0adde1ef3017ba89c867ac909957 |
|
MD5 | 76c6c582281b32c0f23bfa90b8447f22 |
|
BLAKE2b-256 | d19b4cac59253f370ecf96065b204281b05c0cb29b7af72c74dc439a789dadde |