@@ -2386,11 +2386,17 @@ def test_forbid_insecure_gateway(self):
23862386 # By default, we fail immediately if you try to create a SparkContext
23872387 # with an insecure gateway
23882388 gateway = _launch_gateway (insecure = True )
2389- with self .assertRaises (Exception ) as context :
2390- SparkContext (gateway = gateway )
2391- self .assertIn ("insecure Py4j gateway" , str (context .exception ))
2392- self .assertIn ("PYSPARK_ALLOW_INSECURE_GATEWAY" , str (context .exception ))
2393- self .assertIn ("removed in Spark 3.0" , str (context .exception ))
2389+ log4j = gateway .jvm .org .apache .log4j
2390+ old_level = log4j .LogManager .getRootLogger ().getLevel ()
2391+ try :
2392+ log4j .LogManager .getRootLogger ().setLevel (log4j .Level .FATAL )
2393+ with self .assertRaises (Exception ) as context :
2394+ SparkContext (gateway = gateway )
2395+ self .assertIn ("insecure Py4j gateway" , str (context .exception ))
2396+ self .assertIn ("PYSPARK_ALLOW_INSECURE_GATEWAY" , str (context .exception ))
2397+ self .assertIn ("removed in Spark 3.0" , str (context .exception ))
2398+ finally :
2399+ log4j .LogManager .getRootLogger ().setLevel (old_level )
23942400
23952401 def test_allow_insecure_gateway_with_conf (self ):
23962402 with SparkContext ._lock :
@@ -2400,7 +2406,6 @@ def test_allow_insecure_gateway_with_conf(self):
24002406 try :
24012407 os .environ ["PYSPARK_ALLOW_INSECURE_GATEWAY" ] = "1"
24022408 with SparkContext (gateway = gateway ) as sc :
2403- print ("sc created, about to create accum" )
24042409 a = sc .accumulator (1 )
24052410 rdd = sc .parallelize ([1 , 2 , 3 ])
24062411 rdd .foreach (lambda x : a .add (x ))
0 commit comments