From ba8f9b85d3c676a4772077d5dead33a4ec74bd22 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 27 Nov 2025 16:24:11 -0800 Subject: [PATCH] Allow test case pattern for run-tests --- python/docs/source/development/testing.rst | 11 +++++++++++ python/run-tests.py | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/docs/source/development/testing.rst b/python/docs/source/development/testing.rst index dad0ba688072..b64e13b24ce7 100644 --- a/python/docs/source/development/testing.rst +++ b/python/docs/source/development/testing.rst @@ -40,8 +40,19 @@ You can run individual tests by using ``--testnames`` option. For example, .. code-block:: bash + # Run all tests in a module python/run-tests --testnames pyspark.sql.tests.test_dataframe + # Run a specific test case python/run-tests --testnames pyspark.sql.tests.test_dataframe.DataFrameTests.test_range + # Equivalent to the above + python/run-tests --testnames "pyspark.sql.tests.test_dataframe DataFrameTests.test_range" + # You don't need to specify everything, run-tests will do a pattern match + # It uses "-k" for unittest + python/run-tests --testnames "pyspark.sql.tests.test_dataframe test_range" + # This works too + python/run-tests --testnames pyspark.sql.tests.test_dataframe.test_range + # This will match all tests with "range" in their names + python/run-tests --testnames pyspark.sql.tests.test_dataframe.range Note that you may set ``OBJC_DISABLE_INITIALIZE_FORK_SAFETY`` environment variable to ``YES`` if you are running tests on Mac OS. diff --git a/python/run-tests.py b/python/run-tests.py index 83b7d86c11da..0c6a2b77135a 100755 --- a/python/run-tests.py +++ b/python/run-tests.py @@ -144,8 +144,11 @@ def run_individual_python_test(target_dir, test_name, pyspark_python, keep_test_ "Starting test(%s): %s (temp output: %s)", pyspark_python, test_name, per_test_output.name) start_time = time.time() try: + args = test_name.split() + if len(args) == 2: + args.insert(1, "-k") retcode = subprocess.Popen( - [os.path.join(SPARK_HOME, "bin/pyspark")] + test_name.split(), + [os.path.join(SPARK_HOME, "bin/pyspark")] + args, stderr=per_test_output, stdout=per_test_output, env=env).wait() if not keep_test_output: # There exists a race condition in Python and it causes flakiness in MacOS