Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace unittests test cases by pure pytest [Wave-1] #26831

Merged
merged 1 commit into from Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/always/test_secrets.py
Expand Up @@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations

import unittest
from unittest import mock

from airflow.configuration import ensure_secrets_loaded, initialize_secrets_backends
Expand All @@ -26,7 +25,7 @@
from tests.test_utils.db import clear_db_variables


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


class TestVariableFromSecrets(unittest.TestCase):
def setUp(self) -> None:
class TestVariableFromSecrets:
def setup_method(self) -> None:
clear_db_variables()

def tearDown(self) -> None:
def teardown_method(self) -> None:
clear_db_variables()

@mock.patch("airflow.secrets.metastore.MetastoreBackend.get_variable")
Expand Down
21 changes: 11 additions & 10 deletions tests/always/test_secrets_backends.py
Expand Up @@ -18,10 +18,9 @@
from __future__ import annotations

import os
import unittest
from unittest import mock

from parameterized import parameterized
import pytest

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


class TestBaseSecretsBackend(unittest.TestCase):
def setUp(self) -> None:
class TestBaseSecretsBackend:
def setup_method(self) -> None:
clear_db_variables()

def tearDown(self) -> None:
def teardown_method(self) -> None:
clear_db_connections()
clear_db_variables()

@parameterized.expand(
@pytest.mark.parametrize(
"kwargs, output",
[
('default', {"path_prefix": "PREFIX", "secret_id": "ID"}, "PREFIX/ID"),
('with_sep', {"path_prefix": "PREFIX", "secret_id": "ID", "sep": "-"}, "PREFIX-ID"),
]
({"path_prefix": "PREFIX", "secret_id": "ID"}, "PREFIX/ID"),
({"path_prefix": "PREFIX", "secret_id": "ID", "sep": "-"}, "PREFIX-ID"),
],
ids=["default", "with_sep"],
)
def test_build_path(self, _, kwargs, output):
def test_build_path(self, kwargs, output):
build_path = BaseSecretsBackend.build_path
assert build_path(**kwargs) == output

Expand Down