Skip to content

Commit 1c7c976

Browse files
authored
Replace unittests test cases by pure pytest [Wave-1] (#26831)
1 parent 62d5bab commit 1c7c976

File tree

98 files changed

+547
-669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+547
-669
lines changed

tests/always/test_secrets.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# under the License.
1818
from __future__ import annotations
1919

20-
import unittest
2120
from unittest import mock
2221

2322
from airflow.configuration import ensure_secrets_loaded, initialize_secrets_backends
@@ -26,7 +25,7 @@
2625
from tests.test_utils.db import clear_db_variables
2726

2827

29-
class TestConnectionsFromSecrets(unittest.TestCase):
28+
class TestConnectionsFromSecrets:
3029
@mock.patch("airflow.secrets.metastore.MetastoreBackend.get_connection")
3130
@mock.patch("airflow.secrets.environment_variables.EnvironmentVariablesBackend.get_connection")
3231
def test_get_connection_second_try(self, mock_env_get, mock_meta_get):
@@ -112,11 +111,11 @@ def test_backend_fallback_to_env_var(self, mock_get_connection):
112111
assert 'mysql://airflow:airflow@host:5432/airflow' == conn.get_uri()
113112

114113

115-
class TestVariableFromSecrets(unittest.TestCase):
116-
def setUp(self) -> None:
114+
class TestVariableFromSecrets:
115+
def setup_method(self) -> None:
117116
clear_db_variables()
118117

119-
def tearDown(self) -> None:
118+
def teardown_method(self) -> None:
120119
clear_db_variables()
121120

122121
@mock.patch("airflow.secrets.metastore.MetastoreBackend.get_variable")

tests/always/test_secrets_backends.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
from __future__ import annotations
1919

2020
import os
21-
import unittest
2221
from unittest import mock
2322

24-
from parameterized import parameterized
23+
import pytest
2524

2625
from airflow.models.connection import Connection
2726
from airflow.models.variable import Variable
@@ -41,21 +40,23 @@ def __init__(self, conn_id, variation: str):
4140
self.conn = Connection(conn_id=self.conn_id, uri=self.conn_uri)
4241

4342

44-
class TestBaseSecretsBackend(unittest.TestCase):
45-
def setUp(self) -> None:
43+
class TestBaseSecretsBackend:
44+
def setup_method(self) -> None:
4645
clear_db_variables()
4746

48-
def tearDown(self) -> None:
47+
def teardown_method(self) -> None:
4948
clear_db_connections()
5049
clear_db_variables()
5150

52-
@parameterized.expand(
51+
@pytest.mark.parametrize(
52+
"kwargs, output",
5353
[
54-
('default', {"path_prefix": "PREFIX", "secret_id": "ID"}, "PREFIX/ID"),
55-
('with_sep', {"path_prefix": "PREFIX", "secret_id": "ID", "sep": "-"}, "PREFIX-ID"),
56-
]
54+
({"path_prefix": "PREFIX", "secret_id": "ID"}, "PREFIX/ID"),
55+
({"path_prefix": "PREFIX", "secret_id": "ID", "sep": "-"}, "PREFIX-ID"),
56+
],
57+
ids=["default", "with_sep"],
5758
)
58-
def test_build_path(self, _, kwargs, output):
59+
def test_build_path(self, kwargs, output):
5960
build_path = BaseSecretsBackend.build_path
6061
assert build_path(**kwargs) == output
6162

0 commit comments

Comments
 (0)