Skip to content

Commit 3ce8a98

Browse files
committed
use namedtuple instead of mock
1 parent 4edc4b4 commit 3ce8a98

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

python/pyspark/tests/test_context.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
import threading
2121
import time
2222
import unittest
23-
import sys
24-
if sys.version >= '3':
25-
from unittest.mock import MagicMock
26-
else:
27-
from mock import MagicMock
23+
from collections import namedtuple
2824

2925
from pyspark import SparkFiles, SparkContext
3026
from pyspark.testing.utils import ReusedPySparkTestCase, PySparkTestCase, QuietTest, SPARK_HOME
@@ -254,9 +250,8 @@ def test_startTime(self):
254250
def test_forbid_insecure_gateway(self):
255251
# Fail immediately if you try to create a SparkContext
256252
# with an insecure gateway
257-
mock_insecure_gateway = MagicMock()
258-
mock_insecure_gateway.gateway_parameters = MagicMock()
259-
mock_insecure_gateway.gateway_parameters.auth_token = None
253+
parameters = namedtuple('MockGatewayParameters', 'auth_token')(None)
254+
mock_insecure_gateway = namedtuple('MockJavaGateway', 'gateway_parameters')(parameters)
260255
with self.assertRaises(Exception) as context:
261256
SparkContext(gateway=mock_insecure_gateway)
262257
self.assertIn("insecure Py4j gateway", str(context.exception))

0 commit comments

Comments
 (0)