1fanwang commented on code in PR #55817:
URL: https://github.com/apache/spark/pull/55817#discussion_r3493401539
##########
python/pyspark/tests/test_util.py:
##########
@@ -89,6 +91,26 @@ def test_find_spark_home(self):
finally:
os.environ["SPARK_HOME"] = origin
+ @unittest.skipIf(sys.platform == "win32", "find-spark-home is a bash
script")
+ def test_find_spark_home_script_sourceable(self):
+ # SPARK-54434: bin/find-spark-home is documented to be sourced.
+ # When `SPARK_HOME` is already set, the script short-circuits.
+ # The short-circuit must use `return 0` rather than `exit 0`, otherwise
+ # sourcing the script terminates the caller's shell session.
+ script_path = os.path.join(os.environ["SPARK_HOME"], "bin",
"find-spark-home")
+ # Source the script twice and print a marker afterwards. If the script
+ # calls `exit 0` while sourced, the outer shell terminates and the
+ # marker is never emitted.
+ cmd = (
+ f"export SPARK_HOME=/some/value && "
+ f"source {script_path} && "
+ f"source {script_path} && "
+ f"echo SOURCED_OK"
+ )
+ completed = subprocess.run(["bash", "-c", cmd], capture_output=True,
text=True, check=False)
+ self.assertEqual(completed.returncode, 0, msg=completed.stderr)
Review Comment:
Done in 4b38183. Kept the returncode assertion as a sanity
guard (it surfaces stderr if the script errors out), but added a
comment spelling out that `SOURCED_OK` is the real discriminator — a
sourced `exit 0` exits `bash -c` with status 0, so rc is 0 on master
too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]