You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2025/06/23 10:57:07 UTC
(airflow) branch main updated: Removed pytestmark db_test from the spark provider (#52081)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 130e9600443 Removed pytestmark db_test from the spark provider (#52081)
130e9600443 is described below
commit 130e9600443e06c08acc1b28c69a62c858d6e6a2
Author: Dominik <10...@users.noreply.github.com>
AuthorDate: Mon Jun 23 12:57:01 2025 +0200
Removed pytestmark db_test from the spark provider (#52081)
---
.../tests/unit/apache/spark/hooks/test_spark_connect.py | 2 --
.../tests/unit/apache/spark/hooks/test_spark_jdbc.py | 8 ++++++--
.../spark/tests/unit/apache/spark/hooks/test_spark_sql.py | 8 ++++++--
.../tests/unit/apache/spark/hooks/test_spark_submit.py | 15 +++++++++++++--
4 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_connect.py b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_connect.py
index 1174ec2ff48..27d8e8f6d7d 100644
--- a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_connect.py
+++ b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_connect.py
@@ -22,8 +22,6 @@ import pytest
from airflow.models import Connection
from airflow.providers.apache.spark.hooks.spark_connect import SparkConnectHook
-pytestmark = pytest.mark.db_test
-
class TestSparkConnectHook:
@pytest.fixture(autouse=True)
diff --git a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_jdbc.py b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_jdbc.py
index 9f6e034c628..be2b6523bf9 100644
--- a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_jdbc.py
+++ b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_jdbc.py
@@ -24,8 +24,6 @@ import pytest
from airflow.models import Connection
from airflow.providers.apache.spark.hooks.spark_jdbc import SparkJDBCHook
-pytestmark = pytest.mark.db_test
-
class TestSparkJDBCHook:
_config = {
@@ -122,6 +120,7 @@ class TestSparkJDBCHook:
)
)
+ @pytest.mark.db_test
def test_resolve_jdbc_connection(self):
# Given
hook = SparkJDBCHook(jdbc_conn_id="jdbc-default")
@@ -139,6 +138,7 @@ class TestSparkJDBCHook:
# Then
assert connection == expected_connection
+ @pytest.mark.db_test
def test_build_jdbc_arguments(self):
# Given
hook = SparkJDBCHook(**self._config)
@@ -183,6 +183,7 @@ class TestSparkJDBCHook:
]
assert expected_jdbc_arguments == cmd
+ @pytest.mark.db_test
def test_build_jdbc_arguments_invalid(self):
# Given
hook = SparkJDBCHook(**self._invalid_config)
@@ -190,14 +191,17 @@ class TestSparkJDBCHook:
# Expect Exception
hook._build_jdbc_application_arguments(hook._resolve_jdbc_connection())
+ @pytest.mark.db_test
def test_invalid_host(self):
with pytest.raises(ValueError, match="host should not contain a"):
SparkJDBCHook(jdbc_conn_id="jdbc-invalid-host", **self._config)
+ @pytest.mark.db_test
def test_invalid_schema(self):
with pytest.raises(ValueError, match="schema should not contain a"):
SparkJDBCHook(jdbc_conn_id="jdbc-invalid-schema", **self._config)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_submit.SparkSubmitHook.submit")
def test_invalid_extra_conn_prefix(self, mock_submit):
hook = SparkJDBCHook(jdbc_conn_id="jdbc-invalid-extra-conn-prefix", **self._config)
diff --git a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_sql.py b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_sql.py
index 96e69aaeb9a..301ccd730fa 100644
--- a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_sql.py
+++ b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_sql.py
@@ -29,8 +29,6 @@ from airflow.providers.apache.spark.hooks.spark_sql import SparkSqlHook
from tests_common.test_utils.db import clear_db_connections
-pytestmark = pytest.mark.db_test
-
def get_after(sentinel, iterable):
"""Get the value after `sentinel` in an `iterable`"""
@@ -78,6 +76,7 @@ class TestSparkSqlHook:
def teardown_class(cls) -> None:
clear_db_connections(add_default_connections_back=True)
+ @pytest.mark.db_test
def test_build_command(self):
hook = SparkSqlHook(**self._config)
@@ -100,6 +99,7 @@ class TestSparkSqlHook:
if self._config["verbose"]:
assert "--verbose" in cmd
+ @pytest.mark.db_test
def test_build_command_with_str_conf(self):
hook = SparkSqlHook(**self._config_str)
@@ -123,6 +123,7 @@ class TestSparkSqlHook:
if self._config["verbose"]:
assert "--verbose" in cmd
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_sql.subprocess.Popen")
def test_spark_process_runcmd(self, mock_popen):
# Given
@@ -171,6 +172,7 @@ class TestSparkSqlHook:
universal_newlines=True,
)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_sql.subprocess.Popen")
def test_spark_process_runcmd_with_str(self, mock_popen):
# Given
@@ -201,6 +203,7 @@ class TestSparkSqlHook:
universal_newlines=True,
)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_sql.subprocess.Popen")
def test_spark_process_runcmd_with_list(self, mock_popen):
# Given
@@ -231,6 +234,7 @@ class TestSparkSqlHook:
universal_newlines=True,
)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_sql.subprocess.Popen")
def test_spark_process_runcmd_and_fail(self, mock_popen):
# Given
diff --git a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_submit.py b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_submit.py
index b41534baa2f..06a04e55731 100644
--- a/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_submit.py
+++ b/providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_submit.py
@@ -29,8 +29,6 @@ from airflow.exceptions import AirflowException
from airflow.models import Connection
from airflow.providers.apache.spark.hooks.spark_submit import SparkSubmitHook
-pytestmark = pytest.mark.db_test
-
class TestSparkSubmitHook:
_spark_job_file = "test_application.py"
@@ -170,6 +168,7 @@ class TestSparkSubmitHook:
)
)
+ @pytest.mark.db_test
@patch(
"airflow.providers.apache.spark.hooks.spark_submit.os.getenv", return_value="/tmp/airflow_krb5_ccache"
)
@@ -290,6 +289,7 @@ class TestSparkSubmitHook:
assert expected_spark_standalone_cluster == build_track_driver_status_spark_standalone_cluster
assert expected_spark_yarn_cluster == build_track_driver_status_spark_yarn_cluster
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_submit.subprocess.Popen")
def test_spark_process_runcmd(self, mock_popen):
# Given
@@ -310,6 +310,7 @@ class TestSparkSubmitHook:
bufsize=-1,
)
+ @pytest.mark.db_test
def test_resolve_should_track_driver_status(self):
# Given
hook_default = SparkSubmitHook(conn_id="")
@@ -345,6 +346,7 @@ class TestSparkSubmitHook:
assert should_track_driver_status_spark_binary_set is False
assert should_track_driver_status_spark_standalone_cluster is True
+ @pytest.mark.db_test
def test_resolve_connection_yarn_default(self):
# Given
hook = SparkSubmitHook(conn_id="")
@@ -367,6 +369,7 @@ class TestSparkSubmitHook:
assert connection == expected_spark_connection
assert dict_cmd["--master"] == "yarn"
+ @pytest.mark.db_test
def test_resolve_connection_yarn_default_connection(self):
# Given
hook = SparkSubmitHook(conn_id="spark_default")
@@ -560,6 +563,7 @@ class TestSparkSubmitHook:
assert connection == expected_spark_connection
assert cmd[0] == "spark3-submit"
+ @pytest.mark.db_test
def test_resolve_connection_spark_binary_default_value(self):
# Given
hook = SparkSubmitHook(conn_id="spark_default")
@@ -1044,6 +1048,7 @@ class TestSparkSubmitHook:
),
],
)
+ @pytest.mark.db_test
def test_masks_passwords(self, command: str, expected: str) -> None:
# Given
hook = SparkSubmitHook()
@@ -1054,6 +1059,7 @@ class TestSparkSubmitHook:
# Then
assert command_masked == expected
+ @pytest.mark.db_test
def test_create_keytab_path_from_base64_keytab_with_decode_exception(self):
hook = SparkSubmitHook()
invalid_base64 = "invalid_base64"
@@ -1061,6 +1067,7 @@ class TestSparkSubmitHook:
with pytest.raises(AirflowException, match="Failed to decode base64 keytab"):
hook._create_keytab_path_from_base64_keytab(invalid_base64, None)
+ @pytest.mark.db_test
@patch("pathlib.Path.exists")
@patch("builtins.open", new_callable=mock_open)
def test_create_keytab_path_from_base64_keytab_with_write_exception(
@@ -1084,6 +1091,7 @@ class TestSparkSubmitHook:
# Then
assert mock_exists.call_count == 2 # called twice (before write, after write)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_submit.shutil.move")
@patch("pathlib.Path.exists")
@patch("builtins.open", new_callable=mock_open)
@@ -1110,6 +1118,7 @@ class TestSparkSubmitHook:
mock_move.assert_called_once()
assert mock_exists.call_count == 2 # called twice (before write, after write)
+ @pytest.mark.db_test
@patch("airflow.providers.apache.spark.hooks.spark_submit.uuid.uuid4")
@patch("pathlib.Path.resolve")
@patch("airflow.providers.apache.spark.hooks.spark_submit.shutil.move")
@@ -1140,6 +1149,7 @@ class TestSparkSubmitHook:
mock_open().write.assert_called_once_with(keytab_value)
mock_move.assert_called_once()
+ @pytest.mark.db_test
@patch("pathlib.Path.resolve")
@patch("airflow.providers.apache.spark.hooks.spark_submit.shutil.move")
@patch("pathlib.Path.exists")
@@ -1168,6 +1178,7 @@ class TestSparkSubmitHook:
mock_open().write.assert_called_once_with(keytab_value)
mock_move.assert_called_once()
+ @pytest.mark.db_test
@patch("pathlib.Path.resolve")
@patch("pathlib.Path.exists")
@patch("builtins.open", new_callable=mock_open)