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 49cfb6498e Replace `unittests` in microsoft providers tests by pure
`pytest` [Wave-4] (#27735)
49cfb6498e is described below
commit 49cfb6498eed0acfc336a24fd827b69156d5e5bb
Author: Andrey Anshin <[email protected]>
AuthorDate: Fri Nov 18 04:36:02 2022 +0400
Replace `unittests` in microsoft providers tests by pure `pytest` [Wave-4]
(#27735)
---
tests/providers/microsoft/azure/hooks/test_adx.py | 2 +-
.../microsoft/azure/hooks/test_azure_batch.py | 5 ++-
.../azure/hooks/test_azure_container_instance.py | 5 ++-
.../azure/hooks/test_azure_container_registry.py | 4 +--
.../azure/hooks/test_azure_container_volume.py | 3 +-
.../microsoft/azure/hooks/test_azure_cosmos.py | 5 ++-
.../microsoft/azure/hooks/test_azure_data_lake.py | 5 ++-
.../microsoft/azure/hooks/test_azure_fileshare.py | 2 +-
.../microsoft/azure/hooks/test_base_azure.py | 3 +-
tests/providers/microsoft/azure/hooks/test_wasb.py | 2 +-
.../microsoft/azure/operators/test_adls_delete.py | 3 +-
.../microsoft/azure/operators/test_adls_list.py | 3 +-
.../microsoft/azure/operators/test_adx.py | 5 ++-
.../microsoft/azure/operators/test_azure_batch.py | 5 ++-
.../operators/test_azure_container_instances.py | 3 +-
.../microsoft/azure/operators/test_azure_cosmos.py | 5 ++-
.../azure/operators/test_azure_synapse.py | 5 ++-
.../azure/operators/test_wasb_delete_blob.py | 5 ++-
.../azure/secrets/test_azure_key_vault.py | 18 +++++++---
.../microsoft/azure/sensors/test_azure_cosmos.py | 3 +-
.../azure/sensors/test_azure_data_factory.py | 13 ++++---
.../providers/microsoft/azure/sensors/test_wasb.py | 9 +++--
.../azure/transfers/test_azure_blob_to_gcs.py | 3 +-
.../azure/transfers/test_local_to_adls.py | 3 +-
.../azure/transfers/test_local_to_wasb.py | 2 +-
.../transfers/test_oracle_to_azure_data_lake.py | 3 +-
.../providers/microsoft/mssql/hooks/test_mssql.py | 10 +++---
tests/providers/microsoft/psrp/hooks/test_psrp.py | 9 ++---
.../microsoft/psrp/operators/test_psrp.py | 42 +++++++++-------------
.../providers/microsoft/winrm/hooks/test_winrm.py | 3 +-
.../microsoft/winrm/operators/test_winrm.py | 3 +-
31 files changed, 83 insertions(+), 108 deletions(-)
diff --git a/tests/providers/microsoft/azure/hooks/test_adx.py
b/tests/providers/microsoft/azure/hooks/test_adx.py
index e6e9bc3189..22264fe463 100644
--- a/tests/providers/microsoft/azure/hooks/test_adx.py
+++ b/tests/providers/microsoft/azure/hooks/test_adx.py
@@ -37,7 +37,7 @@ ADX_TEST_CONN_ID = "adx_test_connection_id"
class TestAzureDataExplorerHook:
- def teardown(self):
+ def teardown_method(self):
with create_session() as session:
session.query(Connection).filter(Connection.conn_id ==
ADX_TEST_CONN_ID).delete()
diff --git a/tests/providers/microsoft/azure/hooks/test_azure_batch.py
b/tests/providers/microsoft/azure/hooks/test_azure_batch.py
index a4e4f40117..acd6fc53eb 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_batch.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_batch.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
from unittest import mock
from unittest.mock import PropertyMock
@@ -29,9 +28,9 @@ from airflow.providers.microsoft.azure.hooks.batch import
AzureBatchHook
from airflow.utils import db
-class TestAzureBatchHook(unittest.TestCase):
+class TestAzureBatchHook:
# set up the test environment
- def setUp(self):
+ def setup_method(self):
# set up the test variable
self.test_vm_conn_id = "test_azure_batch_vm"
self.test_cloud_conn_id = "test_azure_batch_cloud"
diff --git
a/tests/providers/microsoft/azure/hooks/test_azure_container_instance.py
b/tests/providers/microsoft/azure/hooks/test_azure_container_instance.py
index b7690ca6fe..a10dde9c65 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_container_instance.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_container_instance.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
from unittest.mock import patch
from azure.mgmt.containerinstance.models import (
@@ -34,8 +33,8 @@ from
airflow.providers.microsoft.azure.hooks.container_instance import AzureCont
from airflow.utils import db
-class TestAzureContainerInstanceHook(unittest.TestCase):
- def setUp(self):
+class TestAzureContainerInstanceHook:
+ def setup_method(self):
db.merge_conn(
Connection(
conn_id="azure_container_instance_test",
diff --git
a/tests/providers/microsoft/azure/hooks/test_azure_container_registry.py
b/tests/providers/microsoft/azure/hooks/test_azure_container_registry.py
index 6b1ad50d40..91ae933d2b 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_container_registry.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_container_registry.py
@@ -17,14 +17,12 @@
# under the License.
from __future__ import annotations
-import unittest
-
from airflow.models import Connection
from airflow.providers.microsoft.azure.hooks.container_registry import
AzureContainerRegistryHook
from airflow.utils import db
-class TestAzureContainerRegistryHook(unittest.TestCase):
+class TestAzureContainerRegistryHook:
def test_get_conn(self):
db.merge_conn(
Connection(
diff --git
a/tests/providers/microsoft/azure/hooks/test_azure_container_volume.py
b/tests/providers/microsoft/azure/hooks/test_azure_container_volume.py
index a114695c5e..0a60ec9a37 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_container_volume.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_container_volume.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
from airflow.models import Connection
from airflow.providers.microsoft.azure.hooks.container_volume import
AzureContainerVolumeHook
@@ -26,7 +25,7 @@ from airflow.utils import db
from tests.test_utils.providers import get_provider_min_airflow_version
-class TestAzureContainerVolumeHook(unittest.TestCase):
+class TestAzureContainerVolumeHook:
def test_get_file_volume(self):
db.merge_conn(
Connection(
diff --git a/tests/providers/microsoft/azure/hooks/test_azure_cosmos.py
b/tests/providers/microsoft/azure/hooks/test_azure_cosmos.py
index a81b209ba9..63d134b0b9 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_cosmos.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_cosmos.py
@@ -19,7 +19,6 @@ from __future__ import annotations
import json
import logging
-import unittest
import uuid
from unittest import mock
from unittest.mock import PropertyMock
@@ -34,10 +33,10 @@ from airflow.utils import db
from tests.test_utils.providers import get_provider_min_airflow_version
-class TestAzureCosmosDbHook(unittest.TestCase):
+class TestAzureCosmosDbHook:
# Set up an environment to test with
- def setUp(self):
+ def setup_method(self):
# set up some test variables
self.test_end_point = "https://test_endpoint:443"
self.test_master_key = "magic_test_key"
diff --git a/tests/providers/microsoft/azure/hooks/test_azure_data_lake.py
b/tests/providers/microsoft/azure/hooks/test_azure_data_lake.py
index eadf9883a2..f2b2d5a654 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_data_lake.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_data_lake.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
from unittest import mock
from airflow.models import Connection
@@ -27,8 +26,8 @@ from airflow.utils import db
from tests.test_utils.providers import get_provider_min_airflow_version
-class TestAzureDataLakeHook(unittest.TestCase):
- def setUp(self):
+class TestAzureDataLakeHook:
+ def setup_method(self):
db.merge_conn(
Connection(
conn_id="adl_test_key",
diff --git a/tests/providers/microsoft/azure/hooks/test_azure_fileshare.py
b/tests/providers/microsoft/azure/hooks/test_azure_fileshare.py
index ac5883c79a..dfdc41adaa 100644
--- a/tests/providers/microsoft/azure/hooks/test_azure_fileshare.py
+++ b/tests/providers/microsoft/azure/hooks/test_azure_fileshare.py
@@ -41,7 +41,7 @@ from tests.test_utils.providers import
get_provider_min_airflow_version, object_
class TestAzureFileshareHook:
- def setup(self):
+ def setup_method(self):
db.merge_conn(
Connection(
conn_id="azure_fileshare_test_key",
diff --git a/tests/providers/microsoft/azure/hooks/test_base_azure.py
b/tests/providers/microsoft/azure/hooks/test_base_azure.py
index 300a530d34..7b587c4121 100644
--- a/tests/providers/microsoft/azure/hooks/test_base_azure.py
+++ b/tests/providers/microsoft/azure/hooks/test_base_azure.py
@@ -16,14 +16,13 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest.mock import Mock, patch
from airflow.models import Connection
from airflow.providers.microsoft.azure.hooks.base_azure import AzureBaseHook
-class TestBaseAzureHook(unittest.TestCase):
+class TestBaseAzureHook:
@patch("airflow.providers.microsoft.azure.hooks.base_azure.get_client_from_auth_file")
@patch(
"airflow.providers.microsoft.azure.hooks.base_azure.AzureBaseHook.get_connection",
diff --git a/tests/providers/microsoft/azure/hooks/test_wasb.py
b/tests/providers/microsoft/azure/hooks/test_wasb.py
index be2158461d..8a8c62dc52 100644
--- a/tests/providers/microsoft/azure/hooks/test_wasb.py
+++ b/tests/providers/microsoft/azure/hooks/test_wasb.py
@@ -39,7 +39,7 @@ ACCESS_KEY_STRING = "AccountName=name;skdkskd"
class TestWasbHook:
- def setup(self):
+ def setup_method(self):
db.merge_conn(Connection(conn_id="wasb_test_key", conn_type="wasb",
login="login", password="key"))
self.connection_type = "wasb"
self.connection_string_id = "azure_test_connection_string"
diff --git a/tests/providers/microsoft/azure/operators/test_adls_delete.py
b/tests/providers/microsoft/azure/operators/test_adls_delete.py
index 2e51998024..14ea3b4427 100644
--- a/tests/providers/microsoft/azure/operators/test_adls_delete.py
+++ b/tests/providers/microsoft/azure/operators/test_adls_delete.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from airflow.providers.microsoft.azure.operators.adls import ADLSDeleteOperator
@@ -26,7 +25,7 @@ TASK_ID = "test-adls-list-operator"
TEST_PATH = "test"
-class TestAzureDataLakeStorageDeleteOperator(unittest.TestCase):
+class TestAzureDataLakeStorageDeleteOperator:
@mock.patch("airflow.providers.microsoft.azure.operators.adls.AzureDataLakeHook")
def test_execute(self, mock_hook):
diff --git a/tests/providers/microsoft/azure/operators/test_adls_list.py
b/tests/providers/microsoft/azure/operators/test_adls_list.py
index c2bdb1c10b..e73b1e4200 100644
--- a/tests/providers/microsoft/azure/operators/test_adls_list.py
+++ b/tests/providers/microsoft/azure/operators/test_adls_list.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from airflow.providers.microsoft.azure.operators.adls import ADLSListOperator
@@ -33,7 +32,7 @@ MOCK_FILES = [
]
-class TestAzureDataLakeStorageListOperator(unittest.TestCase):
+class TestAzureDataLakeStorageListOperator:
@mock.patch("airflow.providers.microsoft.azure.operators.adls.AzureDataLakeHook")
def test_execute(self, mock_hook):
mock_hook.return_value.list.return_value = MOCK_FILES
diff --git a/tests/providers/microsoft/azure/operators/test_adx.py
b/tests/providers/microsoft/azure/operators/test_adx.py
index 9ec4c79a79..82e48cd067 100644
--- a/tests/providers/microsoft/azure/operators/test_adx.py
+++ b/tests/providers/microsoft/azure/operators/test_adx.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from azure.kusto.data._models import KustoResultTable
@@ -60,8 +59,8 @@ class MockResponse:
primary_results = [MOCK_RESULT]
-class TestAzureDataExplorerQueryOperator(unittest.TestCase):
- def setUp(self):
+class TestAzureDataExplorerQueryOperator:
+ def setup_method(self):
args = {"owner": "airflow", "start_date": DEFAULT_DATE,
"provide_context": True}
self.dag = DAG(TEST_DAG_ID + "test_schedule_dag_once",
default_args=args, schedule="@once")
diff --git a/tests/providers/microsoft/azure/operators/test_azure_batch.py
b/tests/providers/microsoft/azure/operators/test_azure_batch.py
index f4dc1e9f80..147687b877 100644
--- a/tests/providers/microsoft/azure/operators/test_azure_batch.py
+++ b/tests/providers/microsoft/azure/operators/test_azure_batch.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
from unittest import mock
import pytest
@@ -41,11 +40,11 @@ FORMULA = """$curTime = time();
$TargetDedicated = $isWorkingWeekdayHour ? 20:10;"""
-class TestAzureBatchOperator(unittest.TestCase):
+class TestAzureBatchOperator:
# set up the test environment
@mock.patch("airflow.providers.microsoft.azure.hooks.batch.AzureBatchHook")
@mock.patch("airflow.providers.microsoft.azure.hooks.batch.BatchServiceClient")
- def setUp(self, mock_batch, mock_hook):
+ def setup_method(self, method, mock_batch, mock_hook):
# set up the test variable
self.test_vm_conn_id = "test_azure_batch_vm2"
self.test_cloud_conn_id = "test_azure_batch_cloud2"
diff --git
a/tests/providers/microsoft/azure/operators/test_azure_container_instances.py
b/tests/providers/microsoft/azure/operators/test_azure_container_instances.py
index c193bad585..6c7cd1dbb5 100644
---
a/tests/providers/microsoft/azure/operators/test_azure_container_instances.py
+++
b/tests/providers/microsoft/azure/operators/test_azure_container_instances.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from collections import namedtuple
from unittest import mock
from unittest.mock import MagicMock
@@ -64,7 +63,7 @@ def make_mock_cg_with_missing_events(container_state):
return container_g
-class TestACIOperator(unittest.TestCase):
+class TestACIOperator:
@mock.patch("airflow.providers.microsoft.azure.operators.container_instances.AzureContainerInstanceHook")
def test_execute(self, aci_mock):
expected_c_state = ContainerState(state="Terminated", exit_code=0,
detail_status="test")
diff --git a/tests/providers/microsoft/azure/operators/test_azure_cosmos.py
b/tests/providers/microsoft/azure/operators/test_azure_cosmos.py
index 86b7dedd42..57e5097006 100644
--- a/tests/providers/microsoft/azure/operators/test_azure_cosmos.py
+++ b/tests/providers/microsoft/azure/operators/test_azure_cosmos.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import json
-import unittest
import uuid
from unittest import mock
@@ -27,10 +26,10 @@ from airflow.providers.microsoft.azure.operators.cosmos
import AzureCosmosInsert
from airflow.utils import db
-class TestAzureCosmosDbHook(unittest.TestCase):
+class TestAzureCosmosDbHook:
# Set up an environment to test with
- def setUp(self):
+ def setup_method(self):
# set up some test variables
self.test_end_point = "https://test_endpoint:443"
self.test_master_key = "magic_test_key"
diff --git a/tests/providers/microsoft/azure/operators/test_azure_synapse.py
b/tests/providers/microsoft/azure/operators/test_azure_synapse.py
index f177bb1258..24fadb9dea 100644
--- a/tests/providers/microsoft/azure/operators/test_azure_synapse.py
+++ b/tests/providers/microsoft/azure/operators/test_azure_synapse.py
@@ -17,7 +17,6 @@
from __future__ import annotations
import json
-import unittest
from unittest import mock
from unittest.mock import MagicMock
@@ -39,8 +38,8 @@ CONN_EXTRAS = {
JOB_RUN_RESPONSE = {"id": 123}
-class TestAzureSynapseRunSparkBatchOperator(unittest.TestCase):
- def setUp(self):
+class TestAzureSynapseRunSparkBatchOperator:
+ def setup_method(self):
self.mock_ti = MagicMock()
self.mock_context = {"ti": self.mock_ti}
self.config = {
diff --git a/tests/providers/microsoft/azure/operators/test_wasb_delete_blob.py
b/tests/providers/microsoft/azure/operators/test_wasb_delete_blob.py
index 0f3444e99e..4fee93523f 100644
--- a/tests/providers/microsoft/azure/operators/test_wasb_delete_blob.py
+++ b/tests/providers/microsoft/azure/operators/test_wasb_delete_blob.py
@@ -18,21 +18,20 @@
from __future__ import annotations
import datetime
-import unittest
from unittest import mock
from airflow.models.dag import DAG
from airflow.providers.microsoft.azure.operators.wasb_delete_blob import
WasbDeleteBlobOperator
-class TestWasbDeleteBlobOperator(unittest.TestCase):
+class TestWasbDeleteBlobOperator:
_config = {
"container_name": "container",
"blob_name": "blob",
}
- def setUp(self):
+ def setup_method(self):
args = {"owner": "airflow", "start_date": datetime.datetime(2017, 1,
1)}
self.dag = DAG("test_dag_id", default_args=args)
diff --git a/tests/providers/microsoft/azure/secrets/test_azure_key_vault.py
b/tests/providers/microsoft/azure/secrets/test_azure_key_vault.py
index 3739dae1f4..470d5ae14c 100644
--- a/tests/providers/microsoft/azure/secrets/test_azure_key_vault.py
+++ b/tests/providers/microsoft/azure/secrets/test_azure_key_vault.py
@@ -17,14 +17,15 @@
# under the License.
from __future__ import annotations
-from unittest import TestCase, mock
+from unittest import mock
+import pytest
from azure.core.exceptions import ResourceNotFoundError
from airflow.providers.microsoft.azure.secrets.key_vault import
AzureKeyVaultBackend
-class TestAzureKeyVaultBackend(TestCase):
+class TestAzureKeyVaultBackend:
@mock.patch("airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend.get_conn_value")
def test_get_connection(self, mock_get_value):
mock_get_value.return_value = "scheme://user:pass@host:100"
@@ -44,7 +45,8 @@ class TestAzureKeyVaultBackend(TestCase):
)
backend =
AzureKeyVaultBackend(vault_url="https://example-akv-resource-name.vault.azure.net/")
- returned_uri = backend.get_conn_uri(conn_id="hi")
+ with pytest.warns(DeprecationWarning, match="Method `.*get_conn_uri`
is deprecated"):
+ returned_uri = backend.get_conn_uri(conn_id="hi")
mock_secret_client.assert_called_once_with(
credential=mock_cred,
vault_url="https://example-akv-resource-name.vault.azure.net/"
)
@@ -60,7 +62,8 @@ class TestAzureKeyVaultBackend(TestCase):
mock_client.get_secret.side_effect = ResourceNotFoundError
backend =
AzureKeyVaultBackend(vault_url="https://example-akv-resource-name.vault.azure.net/")
- assert backend.get_conn_uri(conn_id=conn_id) is None
+ with pytest.warns(DeprecationWarning, match="Method `.*get_conn_uri`
is deprecated"):
+ assert backend.get_conn_uri(conn_id=conn_id) is None
assert backend.get_connection(conn_id=conn_id) is None
@mock.patch("airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend.client")
@@ -113,9 +116,14 @@ class TestAzureKeyVaultBackend(TestCase):
kwargs = {"connections_prefix": None}
backend = AzureKeyVaultBackend(**kwargs)
- assert backend.get_conn_uri("test_mysql") is None
+ assert backend.get_connection("test_mysql") is None
mock_get_secret.assert_not_called()
+ mock_get_secret.reset_mock()
+ with pytest.warns(DeprecationWarning, match="Method `.*get_conn_uri`
is deprecated"):
+ assert backend.get_conn_uri("test_mysql") is None
+ mock_get_secret.assert_not_called()
+
@mock.patch("airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend._get_secret")
def test_variable_prefix_none_value(self, mock_get_secret):
"""
diff --git a/tests/providers/microsoft/azure/sensors/test_azure_cosmos.py
b/tests/providers/microsoft/azure/sensors/test_azure_cosmos.py
index 22e49b939d..347dc26372 100644
--- a/tests/providers/microsoft/azure/sensors/test_azure_cosmos.py
+++ b/tests/providers/microsoft/azure/sensors/test_azure_cosmos.py
@@ -16,7 +16,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from airflow.providers.microsoft.azure.sensors.cosmos import
AzureCosmosDocumentSensor
@@ -26,7 +25,7 @@ COLLECTION_NAME = "test-db-collection-name"
DOCUMENT_ID = "test-document-id"
-class TestAzureCosmosSensor(unittest.TestCase):
+class TestAzureCosmosSensor:
@mock.patch("airflow.providers.microsoft.azure.sensors.cosmos.AzureCosmosDBHook")
def test_should_call_hook_with_args(self, mock_hook):
mock_instance = mock_hook.return_value
diff --git a/tests/providers/microsoft/azure/sensors/test_azure_data_factory.py
b/tests/providers/microsoft/azure/sensors/test_azure_data_factory.py
index d1f2719c4a..f695efacef 100644
--- a/tests/providers/microsoft/azure/sensors/test_azure_data_factory.py
+++ b/tests/providers/microsoft/azure/sensors/test_azure_data_factory.py
@@ -16,11 +16,9 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest.mock import patch
import pytest
-from parameterized import parameterized
from airflow.providers.microsoft.azure.hooks.data_factory import (
AzureDataFactoryHook,
@@ -30,8 +28,8 @@ from airflow.providers.microsoft.azure.hooks.data_factory
import (
from airflow.providers.microsoft.azure.sensors.data_factory import
AzureDataFactoryPipelineRunStatusSensor
-class TestPipelineRunStatusSensor(unittest.TestCase):
- def setUp(self):
+class TestPipelineRunStatusSensor:
+ def setup_method(self):
self.config = {
"azure_data_factory_conn_id": "azure_data_factory_test",
"run_id": "run_id",
@@ -50,7 +48,8 @@ class TestPipelineRunStatusSensor(unittest.TestCase):
assert self.sensor.timeout == self.config["timeout"]
assert self.sensor.poke_interval == self.config["poke_interval"]
- @parameterized.expand(
+ @pytest.mark.parametrize(
+ "pipeline_run_status, expected_status",
[
(AzureDataFactoryPipelineRunStatus.SUCCEEDED, True),
(AzureDataFactoryPipelineRunStatus.FAILED, "exception"),
@@ -58,10 +57,10 @@ class TestPipelineRunStatusSensor(unittest.TestCase):
(AzureDataFactoryPipelineRunStatus.CANCELING, False),
(AzureDataFactoryPipelineRunStatus.QUEUED, False),
(AzureDataFactoryPipelineRunStatus.IN_PROGRESS, False),
- ]
+ ],
)
@patch.object(AzureDataFactoryHook, "get_pipeline_run")
- def test_poke(self, pipeline_run_status, expected_status,
mock_pipeline_run):
+ def test_poke(self, mock_pipeline_run, pipeline_run_status,
expected_status):
mock_pipeline_run.return_value.status = pipeline_run_status
if expected_status != "exception":
diff --git a/tests/providers/microsoft/azure/sensors/test_wasb.py
b/tests/providers/microsoft/azure/sensors/test_wasb.py
index 0f52184411..5edc9bcd84 100644
--- a/tests/providers/microsoft/azure/sensors/test_wasb.py
+++ b/tests/providers/microsoft/azure/sensors/test_wasb.py
@@ -18,14 +18,13 @@
from __future__ import annotations
import datetime
-import unittest
from unittest import mock
from airflow.models.dag import DAG
from airflow.providers.microsoft.azure.sensors.wasb import WasbBlobSensor,
WasbPrefixSensor
-class TestWasbBlobSensor(unittest.TestCase):
+class TestWasbBlobSensor:
_config = {
"container_name": "container",
"blob_name": "blob",
@@ -33,7 +32,7 @@ class TestWasbBlobSensor(unittest.TestCase):
"timeout": 100,
}
- def setUp(self):
+ def setup_method(self):
args = {"owner": "airflow", "start_date": datetime.datetime(2017, 1,
1)}
self.dag = DAG("test_dag_id", default_args=args)
@@ -60,7 +59,7 @@ class TestWasbBlobSensor(unittest.TestCase):
mock_instance.check_for_blob.assert_called_once_with("container",
"blob", timeout=2)
-class TestWasbPrefixSensor(unittest.TestCase):
+class TestWasbPrefixSensor:
_config = {
"container_name": "container",
"prefix": "prefix",
@@ -68,7 +67,7 @@ class TestWasbPrefixSensor(unittest.TestCase):
"timeout": 100,
}
- def setUp(self):
+ def setup_method(self):
args = {"owner": "airflow", "start_date": datetime.datetime(2017, 1,
1)}
self.dag = DAG("test_dag_id", default_args=args)
diff --git
a/tests/providers/microsoft/azure/transfers/test_azure_blob_to_gcs.py
b/tests/providers/microsoft/azure/transfers/test_azure_blob_to_gcs.py
index b186496105..0bb5b9535d 100644
--- a/tests/providers/microsoft/azure/transfers/test_azure_blob_to_gcs.py
+++ b/tests/providers/microsoft/azure/transfers/test_azure_blob_to_gcs.py
@@ -16,7 +16,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from airflow.providers.microsoft.azure.transfers.azure_blob_to_gcs import
AzureBlobStorageToGCSOperator
@@ -35,7 +34,7 @@ IMPERSONATION_CHAIN = None
TASK_ID = "transfer_file"
-class TestAzureBlobStorageToGCSTransferOperator(unittest.TestCase):
+class TestAzureBlobStorageToGCSTransferOperator:
def test_init(self):
operator = AzureBlobStorageToGCSOperator(
wasb_conn_id=WASB_CONN_ID,
diff --git a/tests/providers/microsoft/azure/transfers/test_local_to_adls.py
b/tests/providers/microsoft/azure/transfers/test_local_to_adls.py
index ac00ab1289..1ef388eef7 100644
--- a/tests/providers/microsoft/azure/transfers/test_local_to_adls.py
+++ b/tests/providers/microsoft/azure/transfers/test_local_to_adls.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
import pytest
@@ -31,7 +30,7 @@ BAD_LOCAL_PATH = "test/**"
REMOTE_PATH = "TEST-DIR"
-class TestADLSUploadOperator(unittest.TestCase):
+class TestADLSUploadOperator:
@mock.patch("airflow.providers.microsoft.azure.transfers.local_to_adls.AzureDataLakeHook")
def test_execute_success(self, mock_hook):
operator = LocalFilesystemToADLSOperator(
diff --git a/tests/providers/microsoft/azure/transfers/test_local_to_wasb.py
b/tests/providers/microsoft/azure/transfers/test_local_to_wasb.py
index 3a28b16557..fec0854cc3 100644
--- a/tests/providers/microsoft/azure/transfers/test_local_to_wasb.py
+++ b/tests/providers/microsoft/azure/transfers/test_local_to_wasb.py
@@ -36,7 +36,7 @@ class TestLocalFilesystemToWasbOperator:
"retries": 3,
}
- def setup(self):
+ def setup_method(self):
args = {"owner": "airflow", "start_date": datetime.datetime(2017, 1,
1)}
self.dag = DAG("test_dag_id", default_args=args)
diff --git
a/tests/providers/microsoft/azure/transfers/test_oracle_to_azure_data_lake.py
b/tests/providers/microsoft/azure/transfers/test_oracle_to_azure_data_lake.py
index dc65979125..52feffeedf 100644
---
a/tests/providers/microsoft/azure/transfers/test_oracle_to_azure_data_lake.py
+++
b/tests/providers/microsoft/azure/transfers/test_oracle_to_azure_data_lake.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import os
-import unittest
from tempfile import TemporaryDirectory
from unittest import mock
from unittest.mock import MagicMock
@@ -30,7 +29,7 @@ from
airflow.providers.microsoft.azure.transfers.oracle_to_azure_data_lake impor
)
-class TestOracleToAzureDataLakeTransfer(unittest.TestCase):
+class TestOracleToAzureDataLakeTransfer:
mock_module_path =
"airflow.providers.microsoft.azure.transfers.oracle_to_azure_data_lake"
diff --git a/tests/providers/microsoft/mssql/hooks/test_mssql.py
b/tests/providers/microsoft/mssql/hooks/test_mssql.py
index 832fb49754..0b899fe370 100644
--- a/tests/providers/microsoft/mssql/hooks/test_mssql.py
+++ b/tests/providers/microsoft/mssql/hooks/test_mssql.py
@@ -17,11 +17,10 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
from urllib.parse import quote_plus
-from parameterized import parameterized
+import pytest
from airflow.models import Connection
from airflow.providers.microsoft.mssql.hooks.mssql import MsSqlHook
@@ -52,7 +51,7 @@ PYMSSQL_CONN_ALT_2 = Connection(
)
-class TestMsSqlHook(unittest.TestCase):
+class TestMsSqlHook:
@mock.patch("airflow.providers.microsoft.mssql.hooks.mssql.MsSqlHook.get_conn")
@mock.patch("airflow.providers.common.sql.hooks.sql.DbApiHook.get_connection")
def test_get_conn_should_return_connection(self, get_connection,
mssql_get_conn):
@@ -92,7 +91,8 @@ class TestMsSqlHook(unittest.TestCase):
mssql_get_conn.assert_called_once()
assert hook.get_autocommit(conn) == "autocommit_state"
- @parameterized.expand(
+ @pytest.mark.parametrize(
+ "conn, exp_uri",
[
(
PYMSSQL_CONN,
@@ -130,7 +130,7 @@ class TestMsSqlHook(unittest.TestCase):
],
)
@mock.patch("airflow.providers.microsoft.mssql.hooks.mssql.MsSqlHook.get_connection")
- def test_get_uri_driver_rewrite(self, conn, exp_uri, get_connection):
+ def test_get_uri_driver_rewrite(self, get_connection, conn, exp_uri):
get_connection.return_value = conn
hook = MsSqlHook()
diff --git a/tests/providers/microsoft/psrp/hooks/test_psrp.py
b/tests/providers/microsoft/psrp/hooks/test_psrp.py
index 06b7223170..bc1b06aa5f 100644
--- a/tests/providers/microsoft/psrp/hooks/test_psrp.py
+++ b/tests/providers/microsoft/psrp/hooks/test_psrp.py
@@ -18,10 +18,9 @@
from __future__ import annotations
from logging import DEBUG, ERROR, INFO, WARNING
-from unittest import TestCase
from unittest.mock import MagicMock, Mock, call, patch
-from parameterized import parameterized
+import pytest
from pypsrp.host import PSHost
from pypsrp.messages import MessageType
from pypsrp.powershell import PSInvocationState
@@ -111,7 +110,7 @@ def mock_powershell_factory():
@patch(f"{PsrpHook.__module__}.WSMan")
@patch(f"{PsrpHook.__module__}.PowerShell",
new_callable=mock_powershell_factory)
@patch(f"{PsrpHook.__module__}.RunspacePool")
-class TestPsrpHook(TestCase):
+class TestPsrpHook:
def test_get_conn(self, runspace_pool, powershell, ws_man):
hook = PsrpHook(CONNECTION_ID)
assert hook.get_conn() is runspace_pool.return_value
@@ -128,7 +127,9 @@ class TestPsrpHook(TestCase):
with raises(AirflowException, match="Unexpected extra configuration
keys: foo"):
hook.get_conn()
- @parameterized.expand([(None,), (ERROR,)])
+ @pytest.mark.parametrize(
+ "logging_level", [pytest.param(None, id="none"), pytest.param(ERROR,
id="ERROR")]
+ )
def test_invoke(self, runspace_pool, powershell, ws_man, logging_level):
runspace_options = {"connection_name": "foo"}
wsman_options = {"encryption": "auto"}
diff --git a/tests/providers/microsoft/psrp/operators/test_psrp.py
b/tests/providers/microsoft/psrp/operators/test_psrp.py
index 6705701b81..980c7efc8d 100644
--- a/tests/providers/microsoft/psrp/operators/test_psrp.py
+++ b/tests/providers/microsoft/psrp/operators/test_psrp.py
@@ -17,14 +17,11 @@
# under the License.
from __future__ import annotations
-from itertools import product
from typing import Any, NamedTuple
-from unittest import TestCase
from unittest.mock import Mock, call, patch
import pytest
from jinja2.nativetypes import NativeEnvironment
-from parameterized import parameterized
from pypsrp.powershell import Command, PowerShell
from airflow.exceptions import AirflowException
@@ -41,7 +38,7 @@ class ExecuteParameter(NamedTuple):
expected_parameters: dict[str, Any] | None
-class TestPsrpOperator(TestCase):
+class TestPsrpOperator:
def test_no_command_or_powershell(self):
exception_msg = "Must provide exactly one of 'command', 'powershell',
or 'cmdlet'"
with pytest.raises(ValueError, match=exception_msg):
@@ -51,30 +48,23 @@ class TestPsrpOperator(TestCase):
operator = PsrpOperator(cmdlet="Invoke-Foo",
psrp_conn_id=CONNECTION_ID)
assert operator.task_id == "Invoke-Foo"
- @parameterized.expand(
- list(
- product(
- [
- # These tuples map the command parameter to an execution
method
- # and parameter set.
- ExecuteParameter("command", call.add_script("cmd.exe /c
@'\nfoo\n'@"), None),
- ExecuteParameter("powershell", call.add_script("foo"),
None),
- ExecuteParameter("cmdlet", call.add_cmdlet("foo"), {"bar":
"baz"}),
- ],
- [
- (False, 0),
- (False, None),
- (True, None),
- (False, 1),
- (True, 1),
- ],
- [False, True],
- )
- )
+ @pytest.mark.parametrize("do_xcom_push", [True, False])
+ @pytest.mark.parametrize(
+ "had_errors, rc", [(False, 0), (False, None), (True, None), (False,
1), (True, 1)]
+ )
+ @pytest.mark.parametrize(
+ "parameter",
+ [
+ # These tuples map the command parameter to an execution method
and parameter set.
+ pytest.param(
+ ExecuteParameter("command", call.add_script("cmd.exe /c
@'\nfoo\n'@"), None), id="command"
+ ),
+ pytest.param(ExecuteParameter("powershell",
call.add_script("foo"), None), id="powershell"),
+ pytest.param(ExecuteParameter("cmdlet", call.add_cmdlet("foo"),
{"bar": "baz"}), id="cmdlet"),
+ ],
)
@patch(f"{PsrpOperator.__module__}.PsrpHook")
- def test_execute(self, parameter, result, do_xcom_push, hook_impl):
- had_errors, rc = result
+ def test_execute(self, hook_impl, parameter, had_errors, rc, do_xcom_push):
kwargs = {parameter.name: "foo"}
if parameter.expected_parameters:
kwargs["parameters"] = parameter.expected_parameters
diff --git a/tests/providers/microsoft/winrm/hooks/test_winrm.py
b/tests/providers/microsoft/winrm/hooks/test_winrm.py
index 7e0d926fce..906ba91cca 100644
--- a/tests/providers/microsoft/winrm/hooks/test_winrm.py
+++ b/tests/providers/microsoft/winrm/hooks/test_winrm.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest.mock import patch
import pytest
@@ -27,7 +26,7 @@ from airflow.models import Connection
from airflow.providers.microsoft.winrm.hooks.winrm import WinRMHook
-class TestWinRMHook(unittest.TestCase):
+class TestWinRMHook:
@patch("airflow.providers.microsoft.winrm.hooks.winrm.Protocol")
def test_get_conn_exists(self, mock_protocol):
winrm_hook = WinRMHook()
diff --git a/tests/providers/microsoft/winrm/operators/test_winrm.py
b/tests/providers/microsoft/winrm/operators/test_winrm.py
index e5d830de8d..b05ae8f060 100644
--- a/tests/providers/microsoft/winrm/operators/test_winrm.py
+++ b/tests/providers/microsoft/winrm/operators/test_winrm.py
@@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations
-import unittest
from unittest import mock
import pytest
@@ -26,7 +25,7 @@ from airflow.exceptions import AirflowException
from airflow.providers.microsoft.winrm.operators.winrm import WinRMOperator
-class TestWinRMOperator(unittest.TestCase):
+class TestWinRMOperator:
def test_no_winrm_hook_no_ssh_conn_id(self):
op = WinRMOperator(task_id="test_task_id", winrm_hook=None,
ssh_conn_id=None)
exception_msg = "Cannot operate without winrm_hook or ssh_conn_id."