code: def test_add_py_file(self):
      # To ensure that we're actually testing addPyFile's effects, check that
      # this job fails due to `userlibrary` not being on the Python path:
      # disable logging in log4j temporarily
      def func(x):
          from userlibrary import UserClass
  
          return UserClass().hello()
  
      with QuietTest(self.sc):
          self.assertRaises(
              Exception, self.sc.parallelize(range(2)).map(func).first
          )
  
      # Add the file, so the job should now succeed:
      path = os.path.join(
          SPARK_HOME, "python/test_support/userlibrary.py"
      )
      self.sc.addPyFile(path)
      res = self.sc.parallelize(range(2)).map(func).first()
      self.assertEqual("Hello World!", res)
  
imports: import os
  import shutil
  import stat
  import tempfile
  import threading
  import time
  import unittest
  from collections import namedtuple
  from pyspark import SparkConf, SparkFiles, SparkContext
  from pyspark.testing.utils import ReusedPySparkTestCase, PySparkTestCase, QuietTest, SPARK_HOME
label_desc: Use image node_id 1 for calling the AddFileTests obj's underlying member method code with example usage: obj.test_add_py_file() and returns: UserClass