kaxil commented on code in PR #44203:
URL: https://github.com/apache/airflow/pull/44203#discussion_r1849380524


##########
task_sdk/tests/execution_time/test_supervisor.py:
##########
@@ -191,3 +192,44 @@ def subprocess_main():
         assert spy.called_with(id, pid=proc.pid)  # noqa: PGH005
         # The exact number we get will depend on timing behaviour, so be a 
little lenient
         assert 1 <= len(spy.calls) <= 4
+
+    def test_run_simple_dag(self, test_dags_dir, captured_logs, time_machine):
+        """Test running a simple DAG in a subprocess and capturing the 
output."""
+
+        # Ignore anything lower than INFO for this test.
+        
structlog.configure(wrapper_class=structlog.make_filtering_bound_logger(logging.INFO))
+
+        instant = tz.datetime(2024, 11, 7, 12, 34, 56, 78901)
+        time_machine.move_to(instant, tick=False)
+
+        dagfile_path = test_dags_dir / "super_basic_run.py"
+        task_activity = ExecuteTaskActivity(
+            ti=TaskInstance(
+                id=UUID("4d828a62-a417-4936-a7a6-2b3fabacecab"),
+                task_id="hello",
+                dag_id="super_basic_run",
+                run_id="c",
+                try_number=1,
+            ),
+            path=dagfile_path,
+            token="",
+        )
+        # Assert Exit Code is 0
+        assert supervise(activity=task_activity, server="", dry_run=True) == 0
+
+        # We should have 2 logs, one for the DAG parsing and one for the task 
output from the task!
+        assert captured_logs == [
+            {
+                "event": f"Filling up the DagBag from {dagfile_path}",
+                "level": "info",
+                "logger": "airflow.models.dagbag.DagBag",
+                "timestamp": instant.replace(tzinfo=None),
+            },
+            {
+                "chan": "stdout",
+                "event": "Hello World hello!",
+                "level": "info",
+                "logger": "task",
+                "timestamp": "2024-11-07T12:34:56.078901Z",
+            },
+        ]

Review Comment:
   I could also change this to just:
   
   ```python
           assert {
               "chan": "stdout",
               "event": "Hello World hello!",
               "level": "info",
               "logger": "task",
               "timestamp": "2024-11-07T12:34:56.078901Z",
           } in captured_logs
   ```



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