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 just add “spark_home” value to pytest.ini in your project directory:
[pytest] spark_home = /opt/spark
Or set the “SPARK_HOME” environment variable.
pytest-spark will try to import pyspark from specified location.
Order of reading the “spark_home”:
pytest.ini
“SPARK_HOME” environment variable
Try to find it in common locations (i.e. OS X Homebrew)
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.4.1.tar.gz
.
File metadata
- Download URL: pytest-spark-0.4.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e79603b987c45cac9a3cceba35f5816deaf59fbac08af1d3cc5ef4cd246b650b |
|
MD5 | 4a085453775549a0c65da0256055a735 |
|
BLAKE2b-256 | 8c7527bb13cef2fe0acb8e41d01cc323f8f0dc0aeed2e58f9e908cfbc9c09024 |
File details
Details for the file pytest_spark-0.4.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_spark-0.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7442c961d3314a56d149a08734d930cfc594aecfa422b1428b38b90acaa9534f |
|
MD5 | f4b0997e3ad8ab31eace1ad16962cf88 |
|
BLAKE2b-256 | 7e0c953e4a13e234a650f9a47688296e6b081d34b58291eb3feaa7d99715983a |