Skip to content

Commit 4fbcc6d

Browse files
committed
disable log4j during testing when exception is expected.
1 parent cc14202 commit 4fbcc6d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

python/pyspark/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,17 @@ class TestAddFile(PySparkTestCase):
165165
def test_add_py_file(self):
166166
# To ensure that we're actually testing addPyFile's effects, check that
167167
# this job fails due to `userlibrary` not being on the Python path:
168+
# disable logging in log4j temporarily
169+
log4j = self.sc._jvm.org.apache.log4j
170+
old_level = log4j.LogManager.getRootLogger().getLevel()
171+
log4j.LogManager.getRootLogger().setLevel(log4j.Level.FATAL)
168172
def func(x):
169173
from userlibrary import UserClass
170174
return UserClass().hello()
171175
self.assertRaises(Exception,
172176
self.sc.parallelize(range(2)).map(func).first)
177+
log4j.LogManager.getRootLogger().setLevel(old_level)
178+
173179
# Add the file, so the job should now succeed:
174180
path = os.path.join(SPARK_HOME, "python/test_support/userlibrary.py")
175181
self.sc.addPyFile(path)

0 commit comments

Comments
 (0)