ashb commented on code in PR #57631:
URL: https://github.com/apache/airflow/pull/57631#discussion_r2526646347


##########
providers/standard/tests/unit/standard/operators/test_python.py:
##########
@@ -937,6 +937,88 @@ def poke(self, context):
 virtualenv_string_args: list[str] = []
 
 
+def _callable_that_imports_from_bundle():
+    """
+    A callable function for testing DAG bundle imports.
+    This import will fail if PYTHONPATH is not set correctly by the operator.
+    The module 'bug_test_dag_repro' is created dynamically in the test.
+    """
+    try:
+        from bug_test_dag_repro.lib.helper import get_message
+
+        return get_message()
+    except ImportError as e:
+        # This helps debug if the import fails during the test
+        import sys
+
+        return f"Failed to import: {e}. PYTHONPATH: {sys.path}"
+
+
[email protected]_timeout(120)
[email protected](
+    ("opcls", "pytest_marks", "test_class_ref"),
+    [
+        pytest.param(
+            PythonVirtualenvOperator,
+            [pytest.mark.virtualenv_operator],
+            lambda: TestPythonVirtualenvOperator,
+            id="PythonVirtualenvOperator",
+        ),
+        pytest.param(
+            ExternalPythonOperator,
+            [pytest.mark.external_python_operator],
+            lambda: TestExternalPythonOperator,
+            id="ExternalPythonOperator",
+        ),
+    ],
+)
+class TestDagBundleImportInSubprocess(BasePythonTest):
+    """
+    Test DAG bundle imports for subprocess-based Python operators.
+
+    This test ensures that callables running in subprocesses can import modules
+    from their DAG bundle by verifying PYTHONPATH is correctly set (Airflow 
3.x+).
+    """
+
+    @pytest.mark.skipif(not AIRFLOW_V_3_0_PLUS, reason="DAG Bundle import fix 
is for Airflow 3.x+")
+    def test_dag_bundle_import_in_subprocess(self, dag_maker, opcls, 
pytest_marks, test_class_ref):
+        """
+        Tests that a callable in a subprocess can import modules from its
+        own DAG bundle (fix for Airflow 3.x).
+        """
+        with TemporaryDirectory() as tmp_dir:

Review Comment:
   Yes



-- 
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