Repository navigation
[SPARK-62340][PYTHON][TESTS] Add a test for SparkContext constructor arguments and init errors - #60858
Open
gaogaotiantian wants to merge 1 commit into
Open
[SPARK-62340][PYTHON][TESTS] Add a test for SparkContext constructor arguments and init errors#60858gaogaotiantian wants to merge 1 commit into
gaogaotiantian wants to merge 1 commit into
Conversation
Covers the sparkHome, environment and pyFiles arguments, the MASTER_URL_NOT_SET and APPLICATION_NAME_NOT_SET errors, and the warning for an unusable spark.submit.pyFiles entry. Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Adds
ContextTests.test_init_arguments_and_errorstopython/pyspark/tests/test_context.py. It is one test that checks:SparkContext(master, appName, sparkHome=..., pyFiles=[...], environment={...})setsspark.homeandspark.executorEnv.<KEY>on the conf and distributes the py file (SparkFiles.get).SparkContext(conf=SparkConf(loadDefaults=False))raisesMASTER_URL_NOT_SET, and with only a master set raisesAPPLICATION_NAME_NOT_SET.spark.submit.pyFilesentry that does not exist emits theRuntimeWarning"Failed to add file ...".All inputs live in a
tempfile.TemporaryDirectory(), andsys.pathis restored in afinally.Why are the changes needed?
9 lines of
SparkContext._do_initinpython/pyspark/core/context.pywere not covered by any test; this adds coverage for thesparkHome,environmentandpyFilesarguments and for the error and warning paths (spark/python/pyspark/core/context.py
Lines 265 to 283 in d1c23f1
spark/python/pyspark/core/context.py
Lines 354 to 379 in d1c23f1
SparkContextwith no arguments or only master/app name. The test JVM is launched throughspark-submit, which setsspark.masterandspark.app.name, so the missing-setting errors only fire withSparkConf(loadDefaults=False)once the JVM is running.Does this PR introduce any user-facing change?
No, test-only change.
How was this patch tested?
Ran
python/run-tests --testnames 'pyspark.tests.test_context ContextTests.test_init_arguments_and_errors'and the wholepyspark.tests.test_context ContextTestsclass (17 tests); all pass. The new test takes about 1.1s within the class.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-5-5)
This pull request and its description were written by Isaac.