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

Add pytest db_test markers to our tests #35264

Merged
merged 1 commit into from
Oct 30, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions tests/always/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,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 @@ -705,6 +706,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 @@ -34,6 +34,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 @@ -39,6 +39,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
2 changes: 2 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,8 @@
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

if TYPE_CHECKING:
from airflow.models.dag import DAG

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 @@ -37,6 +37,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 @@ -33,6 +33,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
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_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.api_connexion.schemas.dag_schema import (
DAGCollection,
DAGCollectionSchema,
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
2 changes: 2 additions & 0 deletions tests/api_connexion/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from tests.test_utils.db import clear_db_pools
from tests.test_utils.www import client_with_login

pytestmark = pytest.mark.db_test


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

pytestmark = pytest.mark.db_test


class BaseTestAuth:
@pytest.fixture(autouse=True)
Expand Down