potiuk commented on a change in pull request #22311:
URL: https://github.com/apache/airflow/pull/22311#discussion_r829585899



##########
File path: scripts/ci/pre_commit/pre_commit_check_watcher_in_examples.py
##########
@@ -0,0 +1,86 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import sys
+from pathlib import Path
+from typing import List
+
+from rich.console import Console
+
+if __name__ not in ("__main__", "__mp_main__"):
+    raise SystemExit(
+        "This file is intended to be executed as an executable program. You 
cannot use it as a module."
+        f"To run this script, run the ./{__file__} command [FILE] ..."
+    )
+
+
+console = Console(color_system="standard", width=200)
+
+errors: List[str] = []
+
+WATCHER_APPEND_INSTRUCTION = "list(dag.tasks) >> watcher()"
+
+PYTEST_FUNCTION = """
+def test_run():

Review comment:
       That's a nice idea. If pytest still discovers it this way, I lke it a 
lot better. also you can even connect it with local import to make it even more 
localized (same reason as in the other comment , where we care about 
"example_dag" being still an example dag despite also being a self-contained 
test. Also it nicely solves the problem which I thought about - what happens if 
we have two dags in an example. They would have to have slightiy different 
method ( dag1.clear() dag1.run() vs dag2.clear(() dag2.run()). Passing dag as 
parameter solves it nicely.
   
   I'd be for something like this:
   
   ```
        # Needed to run the example dag as system test <link to the docs>
        from tests.airflow.proivders.util import get_test_run
        test_run = get_test_run(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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to