HyukjinKwon commented on code in PR #40793:
URL: https://github.com/apache/spark/pull/40793#discussion_r1168440330


##########
python/pyspark/ml/torch/tests/test_distributor.py:
##########
@@ -382,59 +400,51 @@ def test_end_to_end_run_locally(self) -> None:
 
 @unittest.skipIf(not have_torch, "torch is required")
 class TorchDistributorLocalUnitTests(TorchDistributorLocalUnitTestsMixin, 
unittest.TestCase):
-    def setUp(self) -> None:
-        class_name = self.__class__.__name__
-        conf = self._get_spark_conf()
-        sc = SparkContext("local-cluster[2,2,1024]", class_name, conf=conf)
-        self.spark = SparkSession(sc)
-        self.mnist_dir_path = tempfile.mkdtemp()
+    @classmethod
+    def setUpClass(cls):
+        (gpu_discovery_script_file_name, mnist_dir_path) = set_up_test_dirs()
+        cls.gpu_discovery_script_file_name = gpu_discovery_script_file_name
+        cls.mnist_dir_path = mnist_dir_path
 
-    def tearDown(self) -> None:
-        shutil.rmtree(self.mnist_dir_path)
-        os.unlink(self.gpu_discovery_script_file.name)
-        self.spark.stop()
+        conf = SparkConf()
+        for k, v in get_local_mode_conf().items():
+            conf = conf.set(k, v)
+        conf = conf.set("spark.driver.resource.gpu.discoveryScript", 
gpu_discovery_script_file_name)
+
+        sc = SparkContext("local-cluster[2,2,1024]", 
"TorchDistributorLocalUnitTests", conf=conf)
+        cls.spark = SparkSession(sc)
+
+    @classmethod
+    def tearDownClass(cls):
+        shutil.rmtree(cls.mnist_dir_path)
+        os.unlink(cls.gpu_discovery_script_file_name)
+        cls.spark.stop()
 
 
 @unittest.skipIf(not have_torch, "torch is required")
 class TorchDistributorLocalUnitTestsII(TorchDistributorLocalUnitTestsMixin, 
unittest.TestCase):
-    def setUp(self) -> None:
-        class_name = self.__class__.__name__
-        conf = self._get_spark_conf()
-        sc = SparkContext("local[4]", class_name, conf=conf)
-        self.spark = SparkSession(sc)
-        self.mnist_dir_path = tempfile.mkdtemp()
+    @classmethod
+    def setUpClass(cls):
+        (gpu_discovery_script_file_name, mnist_dir_path) = set_up_test_dirs()
+        cls.gpu_discovery_script_file_name = gpu_discovery_script_file_name

Review Comment:
   ditto:
   
   ```
   (cls.gpu_discovery_script_file_name, cls.mnist_dir_path) = set_up_test_dirs()
   ```



-- 
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]

Reply via email to