Skip to content

Commit

Permalink
Replace unittests test cases by pure pytest [Wave-1] (#26831)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c7c976)
  • Loading branch information
Taragolis authored and ephraimbuddy committed Nov 10, 2022
1 parent 30979ca commit 4815734
Show file tree
Hide file tree
Showing 98 changed files with 547 additions and 669 deletions.
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

0 comments on commit 4815734

Please sign in to comment.