Skip to content

Commit 8cfbc95

Browse files
committed
Move dependency checks to pyspark.testing.utils
Co-authored-by: Isaac
1 parent 08ef647 commit 8cfbc95

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

python/pyspark/sql/tests/streaming/test_streaming_kafka_rtm.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,7 @@
6565
os.environ["PYSPARK_SUBMIT_ARGS"] = " ".join([jars_args, existing_args])
6666

6767
from pyspark.sql.tests.streaming.kafka_utils import KafkaUtils
68-
69-
70-
# Check if required Python dependencies are available
71-
try:
72-
import testcontainers # noqa: F401
73-
import kafka # noqa: F401
74-
75-
have_kafka_deps = True
76-
except ImportError:
77-
have_kafka_deps = False
68+
from pyspark.testing.utils import have_testcontainers, have_kafka
7869

7970

8071
class StreamingKafkaTestsMixin:
@@ -122,7 +113,7 @@ def _is_docker_available():
122113

123114

124115
@unittest.skipIf(
125-
not have_kafka_deps,
116+
not (have_testcontainers and have_kafka),
126117
"Kafka test dependencies not available (testcontainers, kafka-python)",
127118
)
128119
class StreamingKafkaTests(StreamingKafkaTestsMixin, ReusedSQLTestCase):

python/pyspark/testing/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def have_package(name: str) -> bool:
103103
have_zstandard = have_package("zstandard")
104104
zstandard_requirement_message = "" if have_zstandard else "No module named 'zstandard'"
105105

106+
have_testcontainers = have_package("testcontainers")
107+
testcontainers_requirement_message = (
108+
"" if have_testcontainers else "No module named 'testcontainers'"
109+
)
110+
111+
have_kafka = have_package("kafka")
112+
kafka_requirement_message = "" if have_kafka else "No module named 'kafka'"
113+
106114

107115
googleapis_common_protos_requirement_message = ""
108116

0 commit comments

Comments
 (0)