Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions tests/integrations/spark/test_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def sentry_init_with_reset(sentry_init):
_processed_integrations.discard("spark")


@pytest.fixture(scope="function")
@pytest.fixture(scope="session")
def create_spark_context():
conf = SparkConf().set("spark.driver.bindAddress", "127.0.0.1")
yield lambda: SparkContext(conf=conf, appName="Testing123")
SparkContext._active_spark_context.stop()
sc = SparkContext(conf=conf, appName="Testing123")
yield lambda: sc
sc.stop()


def test_set_app_properties(create_spark_context):
Expand Down Expand Up @@ -61,12 +62,18 @@ def test_start_sentry_listener(create_spark_context):
def test_initialize_spark_integration_before_spark_context_init(
mock_patch_spark_context_init,
sentry_init_with_reset,
create_spark_context,
):
sentry_init_with_reset()
create_spark_context()

mock_patch_spark_context_init.assert_called_once()
# As we are using the same SparkContext connection for the whole session,
# we clean it during this test.
original_context = SparkContext._active_spark_context
SparkContext._active_spark_context = None

try:
sentry_init_with_reset()
mock_patch_spark_context_init.assert_called_once()
finally:
# Restore the original one.
SparkContext._active_spark_context = original_context


@patch("sentry_sdk.integrations.spark.spark_driver._activate_integration")
Expand Down