Skip to content

Commit

Permalink
Add pytest db_test markers to our tests (#35264)
Browse files Browse the repository at this point in the history
This PR is separated out from #35160 in order to make the big
refactor and splitting out our test harness to DB and Non-DB
tests far more easy to review.

This change contains purely adding db_tests markers to the tests
that need them, and as such it requires very litte effort to
review. Once this one is merged hoever, the #35160 will become
way smaller in terms of number of files to review, which will
make it far easier to review using GitHub Interface.

(cherry picked from commit 1aa91a4)
  • Loading branch information
potiuk authored and ephraimbuddy committed Nov 1, 2023
1 parent c933cb8 commit 3fbe00a
Show file tree
Hide file tree
Showing 389 changed files with 1,072 additions and 5 deletions.
2 changes: 2 additions & 0 deletions tests/always/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def test_param_setup(self):
assert "airflow" == conn.password
assert conn.port is None

@pytest.mark.db_test
def test_env_var_priority(self):
conn = SqliteHook.get_connection(conn_id="airflow_db")
assert "ec2.compute.com" != conn.host
Expand Down Expand Up @@ -706,6 +707,7 @@ def test_connection_mixed(self):
):
Connection(conn_id="TEST_ID", uri="mysql://", schema="AAA")

@pytest.mark.db_test
def test_masking_from_db(self):
"""Test secrets are masked when loaded directly from the DB"""
from airflow.settings import Session
Expand Down
2 changes: 2 additions & 0 deletions tests/always/test_example_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def relative_path(path):
return os.path.relpath(path, AIRFLOW_SOURCES_ROOT.as_posix())


@pytest.mark.db_test
@pytest.mark.parametrize("example", example_not_suspended_dags(), ids=relative_path)
def test_should_be_importable(example):
dagbag = DagBag(
Expand All @@ -87,6 +88,7 @@ def test_should_be_importable(example):
assert len(dagbag.dag_ids) >= 1


@pytest.mark.db_test
@pytest.mark.parametrize("example", example_dags_except_db_exception(), ids=relative_path)
def test_should_not_do_database_queries(example):
with assert_queries_count(0):
Expand Down
3 changes: 3 additions & 0 deletions tests/always/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from unittest import mock

import pytest

from airflow.configuration import ensure_secrets_loaded, initialize_secrets_backends
from airflow.models import Connection, Variable
from airflow.secrets.cache import SecretCache
Expand Down Expand Up @@ -115,6 +117,7 @@ def test_backend_fallback_to_env_var(self, mock_get_connection):
assert "mysql://airflow:airflow@host:5432/airflow" == conn.get_uri()


@pytest.mark.db_test
class TestVariableFromSecrets:
def setup_method(self) -> None:
clear_db_variables()
Expand Down
2 changes: 2 additions & 0 deletions tests/always/test_secrets_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from airflow.utils.session import create_session
from tests.test_utils.db import clear_db_connections, clear_db_variables

pytestmark = pytest.mark.db_test


class SampleConn:
def __init__(self, conn_id, variation: str):
Expand Down
3 changes: 3 additions & 0 deletions tests/api_connexion/endpoints/test_config_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.config import conf_vars

pytestmark = pytest.mark.db_test


MOCK_CONF = {
"core": {
"parallelism": "1024",
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_connection_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from tests.test_utils.db import clear_db_connections
from tests.test_utils.www import _check_last_log

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_dag_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags

pytestmark = pytest.mark.db_test


@pytest.fixture()
def current_file_token(url_safe_serializer) -> str:
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_dag_run_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags
from tests.test_utils.www import _check_last_log

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
3 changes: 3 additions & 0 deletions tests/api_connexion/endpoints/test_dag_source_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.db import clear_db_dag_code, clear_db_dags, clear_db_serialized_dags

pytestmark = pytest.mark.db_test


ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
EXAMPLE_DAG_FILE = os.path.join("airflow", "example_dags", "example_bash_operator.py")

Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_dag_warning_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.db import clear_db_dag_warnings, clear_db_dags

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_dataset_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_datasets, clear_db_runs

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_event_log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_logs

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_extra_link_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from tests.test_utils.db import clear_db_runs, clear_db_xcom
from tests.test_utils.mock_plugins import mock_plugin_manager

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_health_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
HEALTHY = "healthy"
UNHEALTHY = "unhealthy"

pytestmark = pytest.mark.db_test


class TestHealthTestBase:
@pytest.fixture(autouse=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_import_error_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_import_errors

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.db import clear_db_runs

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from tests.test_utils.db import clear_db_runs, clear_db_sla_miss, clear_rendered_ti_fields
from tests.test_utils.mock_operators import MockOperator

pytestmark = pytest.mark.db_test

DEFAULT_DATETIME_1 = datetime(2020, 1, 1)
DEFAULT_DATETIME_STR_1 = "2020-01-01T00:00:00+00:00"
DEFAULT_DATETIME_STR_2 = "2020-01-02T00:00:00+00:00"
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_plugin_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.mock_plugins import mock_plugin_manager

pytestmark = pytest.mark.db_test


class PluginHook(BaseHook):
...
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_pool_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_pools

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_provider_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from airflow.security import permissions
from tests.test_utils.api_connexion_utils import create_user, delete_user

pytestmark = pytest.mark.db_test

MOCK_PROVIDERS = {
"apache-airflow-providers-amazon": ProviderInfo(
"1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
delete_user,
)

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_task_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_task_instance_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_roles, delete_user
from tests.test_utils.db import clear_db_runs, clear_db_sla_miss, clear_rendered_ti_fields

pytestmark = pytest.mark.db_test

DEFAULT_DATETIME_1 = datetime(2020, 1, 1)
DEFAULT_DATETIME_STR_1 = "2020-01-01T00:00:00+00:00"
DEFAULT_DATETIME_STR_2 = "2020-01-02T00:00:00+00:00"
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_user_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
from tests.test_utils.config import conf_vars

pytestmark = pytest.mark.db_test

DEFAULT_TIME = "2020-06-11T18:00:00+00:00"


Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_variable_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from tests.test_utils.db import clear_db_variables
from tests.test_utils.www import _check_last_log

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_version_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import pytest

pytestmark = pytest.mark.db_test


class TestGetHealthTest:
@pytest.fixture(autouse=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/endpoints/test_xcom_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_db_xcom

pytestmark = pytest.mark.db_test


class CustomXCom(BaseXCom):
@classmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_connection_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from airflow.utils.session import create_session, provide_session
from tests.test_utils.db import clear_db_connections

pytestmark = pytest.mark.db_test


class TestConnectionCollectionItemSchema:
def setup_method(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_dag_run_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

SECOND_TIME = "2020-06-10T13:59:56.336000+00:00"

pytestmark = pytest.mark.db_test


class TestDAGRunBase:
def setup_method(self) -> None:
Expand Down
3 changes: 3 additions & 0 deletions tests/api_connexion/schemas/test_dag_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from datetime import datetime

import pytest

from airflow import DAG
from airflow.api_connexion.schemas.dag_schema import (
DAGCollection,
Expand Down Expand Up @@ -141,6 +143,7 @@ def test_serialize_test_dag_collection_schema(url_safe_serializer):
} == schema.dump(instance)


@pytest.mark.db_test
def test_serialize_test_dag_detail_schema(url_safe_serializer):
dag = DAG(
dag_id="test_dag",
Expand Down
3 changes: 3 additions & 0 deletions tests/api_connexion/schemas/test_dataset_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations

import pytest
import time_machine

from airflow.api_connexion.schemas.dataset_schema import (
Expand All @@ -31,6 +32,8 @@
from airflow.operators.empty import EmptyOperator
from tests.test_utils.db import clear_db_dags, clear_db_datasets

pytestmark = pytest.mark.db_test


class TestDatasetSchemaBase:
def setup_method(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions tests/api_connexion/schemas/test_error_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# under the License.
from __future__ import annotations

import pytest

from airflow.api_connexion.schemas.error_schema import (
ImportErrorCollection,
import_error_collection_schema,
Expand All @@ -26,6 +28,8 @@
from airflow.utils.session import provide_session
from tests.test_utils.db import clear_db_import_errors

pytestmark = pytest.mark.db_test


class TestErrorSchemaBase:
def setup_method(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_event_log_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from airflow.models import Log
from airflow.utils import timezone

pytestmark = pytest.mark.db_test


@pytest.fixture
def task_instance(session, create_task_instance, request):
Expand Down
4 changes: 4 additions & 0 deletions tests/api_connexion/schemas/test_pool_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
# under the License.
from __future__ import annotations

import pytest

from airflow.api_connexion.schemas.pool_schema import PoolCollection, pool_collection_schema, pool_schema
from airflow.models.pool import Pool
from airflow.utils.session import provide_session
from tests.test_utils.db import clear_db_pools

pytestmark = pytest.mark.db_test


class TestPoolSchema:
def setup_method(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from airflow.security import permissions
from tests.test_utils.api_connexion_utils import create_role, delete_role

pytestmark = pytest.mark.db_test


class TestRoleCollectionItemSchema:
@pytest.fixture(scope="class")
Expand Down
1 change: 1 addition & 0 deletions tests/api_connexion/schemas/test_task_instance_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from airflow.utils.timezone import datetime


@pytest.mark.db_test
class TestTaskInstanceSchema:
@pytest.fixture(autouse=True)
def set_attrs(self, session, dag_maker):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_user_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

DEFAULT_TIME = "2021-01-09T13:59:56.336000+00:00"

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module")
def configured_app(minimal_app_for_api):
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_xcom_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from airflow.utils.dates import parse_execution_date
from airflow.utils.session import create_session

pytestmark = pytest.mark.db_test


@pytest.fixture(scope="module", autouse=True)
def clean_xcom():
Expand Down

0 comments on commit 3fbe00a

Please sign in to comment.