Skip to content

Commit

Permalink
Note in pytest_plugin to not global import Airflow (#43738)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Nov 7, 2024
1 parent c83e72a commit 845a160
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests_common/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@

Op = TypeVar("Op", bound=BaseOperator)

# NOTE: DO NOT IMPORT AIRFLOW THINGS HERE!
#
# This plugin is responsible for configuring Airflow correctly to run tests.
# Importing Airflow here loads Airflow too eagerly and break the configurations.
# Instead, import what you want lazily inside a fixture function.
#
# Be aware that many things in tests_common also indirectly imports Airflow, so
# those modules also should not be imported globally.
#
# (Things in the TYPE_CHECKING block are fine because they are not actually
# imported at runtime; those imports are only hints to the type checker.)

assert "airflow" not in sys.modules, (
"Airflow SHOULD NOT have been imported at this point! "
"Read comments in pytest_plugin.py to understand more."
)

# https://docs.pytest.org/en/stable/reference/reference.html#stash
capture_warnings_key = pytest.StashKey["CaptureWarningsPlugin"]()
forbidden_warnings_key = pytest.StashKey["ForbiddenWarningsPlugin"]()
Expand Down

0 comments on commit 845a160

Please sign in to comment.