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” environmental variable.
pytest-spark will try to import pyspark from specified location.
Order of reading spark_home:
pytest.ini
“SPARK_HOME” environmental 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")
# ...
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest-spark-0.4.0.tar.gz.
File metadata
- Download URL: pytest-spark-0.4.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d351b06f946406ae963778735edc00237ea25cc04caa2c4d10338e7d034456
|
|
| MD5 |
424d1d761472679faaf63f4316d8021c
|
|
| BLAKE2b-256 |
5e2b795eff24c2170573e1d1d3c2a08a393e9184a2b8aed4da6ceae78854a2e5
|
File details
Details for the file pytest_spark-0.4.0-py2.py3-none-any.whl.
File metadata
- Download URL: pytest_spark-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad4c701f76c6b90e7a76f0ff52f6752243dc4876bfff6e56f51c370a69587d08
|
|
| MD5 |
73397cda982251c2161229ce97a097e2
|
|
| BLAKE2b-256 |
6011eb3c4422aa8cb6b6c66f73620e37c5a73ed5708d9fb69d5dd2abc5d0a8b3
|