rjgoyln commented on code in PR #72810:
URL: https://github.com/apache/airflow/pull/72810#discussion_r3970722268
##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -969,6 +970,23 @@ def test_dag_test_show_dag(self, mock_get_dag,
mock_render_dag, stdout_capture):
mock_render_dag.assert_has_calls([mock.call(mock_get_dag.return_value,
tis=[])])
assert "SOURCE" in output
+ @mock.patch("airflow.cli.commands.dag_command.render_dag", autospec=True)
+ @mock.patch.object(DAG, "test", autospec=True)
+ def test_dag_test_show_dag_from_dag_cli(self, mock_test, mock_render_dag,
dag_maker):
+ """``DAG.cli()`` passes the Dag positionally and its parser drops
``dag_id``."""
+ with dag_maker("dag_cli_show_dagrun", schedule=None) as dag:
+ EmptyOperator(task_id="only_task")
+ mock_test.return_value = dag_maker.create_dagrun(run_id="dag_cli_run")
+
+ parser = cli_parser.get_parser(dag_parser=True)
+ dag_command.dag_test(parser.parse_args(["dags", "test",
"--show-dagrun"]), dag)
Review Comment:
With `render_dag` autospecced, `dot_graph.source` is a mock attribute, so
the run prints `<MagicMock name='render_dag().source' id=...>` to stdout —
visible under `-s`. `test_dag_test_show_dag` just above takes `stdout_capture`
for exactly that, and line 310 in this file already uses the bare form.
```suggestion
def test_dag_test_show_dag_from_dag_cli(self, mock_test,
mock_render_dag, dag_maker, stdout_capture):
"""``DAG.cli()`` passes the Dag positionally and its parser drops
``dag_id``."""
with dag_maker("dag_cli_show_dagrun", schedule=None) as dag:
EmptyOperator(task_id="only_task")
mock_test.return_value =
dag_maker.create_dagrun(run_id="dag_cli_run")
parser = cli_parser.get_parser(dag_parser=True)
with stdout_capture:
dag_command.dag_test(parser.parse_args(["dags", "test",
"--show-dagrun"]), dag)
```
--
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]