potiuk commented on code in PR #43738:
URL: https://github.com/apache/airflow/pull/43738#discussion_r1831068782


##########
tests_common/pytest_plugin.py:
##########
@@ -31,6 +31,18 @@
 import pytest
 import time_machine
 
+# 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.)

Review Comment:
   Absolutely - we already have this in conftest.py:
   
   ```
   # We should set these before loading _any_ of the rest of airflow so that the
   # unit test mode config is set as early as possible.
   assert "airflow" not in sys.modules, "No airflow module can be imported 
before these lines"
   ```



##########
tests_common/pytest_plugin.py:
##########
@@ -31,6 +31,18 @@
 import pytest
 import time_machine
 
+# 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.)

Review Comment:
   Absolutely - we already have this in conftest.py:
   
   ```python
   # We should set these before loading _any_ of the rest of airflow so that the
   # unit test mode config is set as early as possible.
   assert "airflow" not in sys.modules, "No airflow module can be imported 
before these lines"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to