Skip to content

Commit

Permalink
Extract version compatibility constant in tests to version_compat (#4…
Browse files Browse the repository at this point in the history
…4774)

This is extracted out of #44686 - pre-requisite for consistency
check and consistency change to always use version_compat embedded in
providers and avoid mistakes with importing the compat from tests
in the providers code.

This is purely extraction of constants that use to be in compat module
to version_compat - which will make it easy to write the pre-commit
to check if version_compat from tests_modules is used accidentally.
  • Loading branch information
potiuk authored Dec 8, 2024
1 parent 088e796 commit a31188a
Show file tree
Hide file tree
Showing 113 changed files with 163 additions and 129 deletions.
4 changes: 2 additions & 2 deletions contributing-docs/testing/unit_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,12 @@ are not part of the public API. We deal with it in one of the following ways:
you can add more if needed in a similar way.

3) If only some tests are not compatible and use features that are available only in newer airflow version,
we can mark those tests with appropriate ``AIRFLOW_V_2_X_PLUS`` boolean constant defined in ``compat.py``
we can mark those tests with appropriate ``AIRFLOW_V_2_X_PLUS`` boolean constant defined in ``version_compat.py``
For example:

.. code-block:: python
from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS
@pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="The tests should be skipped for Airflow < 2.9")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
from airflow.www import app as application
from airflow.www.extensions.init_appbuilder import init_appbuilder

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.www import check_content_in_response

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/auth_manager/views/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from airflow.exceptions import AirflowException
from airflow.www import app as application

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS

pytestmark = pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Test requires Airflow 2.9+")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
from airflow.version import version as airflow_version_str

from tests_common import RUNNING_TESTS_AGAINST_AIRFLOW_PACKAGES
from tests_common.test_utils.compat import AIRFLOW_V_2_10_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_2_10_PLUS

pytestmark = pytest.mark.db_test

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/hooks/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from airflow.utils.timezone import datetime

from tests_common.test_utils.compat import AIRFLOW_V_2_10_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_2_10_PLUS


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/links/test_base_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from airflow.providers.amazon.aws.links.base_aws import BaseAwsLink
from airflow.serialization.serialized_objects import SerializedDAG

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.mock_operators import MockOperator
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

if TYPE_CHECKING:
from airflow.models.taskinstance import TaskInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
from airflow.utils.state import State
from airflow.utils.timezone import datetime

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS


def get_time_str(time_in_milliseconds):
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/log/test_s3_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from airflow.utils.state import State, TaskInstanceState
from airflow.utils.timezone import datetime

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS


@pytest.fixture(autouse=True)
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/operators/test_athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from airflow.utils.types import DagRunType

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

TEST_DAG_ID = "unit_tests"
DEFAULT_DATE = datetime(2018, 1, 1)
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/operators/test_datasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from airflow.utils.types import DagRunType

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

TEST_DAG_ID = "unit_tests"
DEFAULT_DATE = datetime(2018, 1, 1)
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/operators/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from airflow.utils.types import DagRunType

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

TASK_ARN = "test_arn"

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/operators/test_emr_add_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from airflow.utils.types import DagRunType

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = timezone.datetime(2017, 1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from providers.tests.amazon.aws.utils.test_waiter import assert_expected_waiter_type
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

TASK_ID = "test_task"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from airflow.utils.types import DagRunType

from providers.tests.amazon.aws.utils.test_template_fields import validate_template_fields
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

CONFIG: dict = {
"key1": "1",
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/sensors/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = datetime(2015, 1, 1)

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/transfers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = timezone.datetime(2020, 1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS


class TestJSONEncoder:
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/amazon/aws/transfers/test_mongo_to_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

TASK_ID = "test_mongo_to_s3_operator"
MONGO_CONN_ID = "default_mongo"
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/apache/hive/hooks/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
MockSubProcess,
)
from tests_common.test_utils.asserts import assert_equal_ignore_multiple_spaces
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = timezone.datetime(2015, 1, 1)
DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/apache/kylin/operators/test_kylin_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = timezone.datetime(2020, 1, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from airflow.utils import timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

DEFAULT_DATE = timezone.datetime(2017, 1, 1)

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/celery/cli/test_celery_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from airflow.executors import executor_loader
from airflow.providers.celery.cli import celery_command

from tests_common.test_utils.compat import AIRFLOW_V_2_10_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_2_10_PLUS

pytestmark = pytest.mark.db_test

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/celery/executors/test_celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
from airflow.utils.state import State

from tests_common.test_utils import db
from tests_common.test_utils.compat import AIRFLOW_V_2_10_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_2_10_PLUS

pytestmark = pytest.mark.db_test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
from airflow.utils.timezone import datetime
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS, PythonOperator
from tests_common.test_utils.compat import PythonOperator
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

if AIRFLOW_V_3_0_PLUS:
from airflow.utils.types import DagRunTriggeredByType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from airflow.utils import db, timezone
from airflow.utils.types import DagRunType

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS


@patch("airflow.providers.cncf.kubernetes.operators.spark_kubernetes.KubernetesHook")
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/cncf/kubernetes/test_pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
from airflow.providers.cncf.kubernetes.secret import Secret

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

now = pendulum.now("UTC")

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/common/compat/lineage/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from airflow.providers.common.compat.lineage.hook import get_hook_lineage_collector

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS


def test_that_compat_does_not_raise():
Expand Down
3 changes: 2 additions & 1 deletion providers/tests/common/io/xcom/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import pytest

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS, ignore_provider_compatibility_error
from tests_common.test_utils.compat import ignore_provider_compatibility_error
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS

pytestmark = [
pytest.mark.db_test,
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/common/sql/operators/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
from airflow.utils.session import create_session
from airflow.utils.state import State

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.providers import get_provider_min_airflow_version
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

if AIRFLOW_V_3_0_PLUS:
from airflow.utils.types import DagRunTriggeredByType
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/common/sql/sensors/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from airflow.providers.common.sql.sensors.sql import SqlSensor
from airflow.utils.timezone import datetime

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS

pytestmark = pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Tests for Airflow 2.8.0+ only")

Expand Down
2 changes: 1 addition & 1 deletion providers/tests/elasticsearch/log/test_es_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@

from providers.tests.elasticsearch.log.elasticmock import elasticmock
from providers.tests.elasticsearch.log.elasticmock.utilities import SearchFailedException
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.db import clear_db_dags, clear_db_runs
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

pytestmark = pytest.mark.db_test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from airflow.providers.fab.auth_manager.api.auth.backend.basic_auth import requires_authentication
from airflow.www import app as application

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS

pytestmark = [
pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Tests for Airflow 2.9.0+ only"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from airflow.providers.fab.auth_manager.api.auth.backend.session import requires_authentication
from airflow.www import app as application

from tests_common.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests_common.test_utils.version_compat import AIRFLOW_V_2_9_PLUS

pytestmark = [
pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Tests for Airflow 2.9.0+ only"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from airflow.utils import timezone

from providers.tests.fab.auth_manager.api_endpoints.api_connexion_utils import create_user, delete_user
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_assets, clear_db_runs
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.www import _check_last_log

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from flask_login import current_user

from tests_common.test_utils.api_connexion_utils import assert_401
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.db import clear_db_pools
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.www import client_with_login

pytestmark = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import pytest

from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.config import conf_vars
from tests_common.test_utils.db import clear_db_pools
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

pytestmark = [
pytest.mark.db_test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from airflow.utils.session import provide_session

from providers.tests.fab.auth_manager.api_endpoints.api_connexion_utils import create_user, delete_user
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.www import _check_last_log

pytestmark = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
delete_roles,
delete_user,
)
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

try:
from airflow.utils.types import DagRunTriggeredByType, DagRunType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from airflow.security import permissions

from providers.tests.fab.auth_manager.api_endpoints.api_connexion_utils import create_user, delete_user
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_dag_code, clear_db_dags, clear_db_serialized_dags
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

pytestmark = [
pytest.mark.db_test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from airflow.utils.session import create_session

from providers.tests.fab.auth_manager.api_endpoints.api_connexion_utils import create_user, delete_user
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_dag_warnings, clear_db_dags
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

pytestmark = [
pytest.mark.db_test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from airflow.utils import timezone

from providers.tests.fab.auth_manager.api_endpoints.api_connexion_utils import create_user, delete_user
from tests_common.test_utils.compat import AIRFLOW_V_3_0_PLUS
from tests_common.test_utils.db import clear_db_logs
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS

pytestmark = [
pytest.mark.db_test,
Expand Down
Loading

0 comments on commit a31188a

Please sign in to comment.