Am
15. September 2026 erreichen alle Cloud Composer 1- und Cloud Composer 2-Umgebungen der Version 2.0.x das geplante Ende des Lebenszyklus und können nicht mehr verwendet werden. Wir empfehlen, die
Migration zu Cloud Composer 3 zu planen.
DAG-Einheitentests
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Beispiel für einen Einheitentest für einen Python-DAG.
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser vonGoogle Cloud verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code demonstrates how to create a unit test for a Python Directed Acyclic Graph (DAG) in Airflow.\u003c/p\u003e\n"],["\u003cp\u003eThe test validates that a module contains a valid DAG and detects any task cycles within it using the \u003ccode\u003etest_cycle\u003c/code\u003e function.\u003c/p\u003e\n"],["\u003cp\u003eApplication Default Credentials are required to authenticate to Cloud Composer.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud sample browser can be used to discover more examples.\u003c/p\u003e\n"]]],[],null,["A sample unit test for a Python DAG.\n\nCode sample \n\nPython\n\n\nTo authenticate to Cloud Composer, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from airflow import models\n from airflow.utils.dag_cycle_tester import test_cycle\n\n\n def assert_has_valid_dag(module):\n \"\"\"Assert that a module contains a valid DAG.\"\"\"\n\n no_dag_found = True\n\n for dag in vars(module).values():\n if isinstance(dag, models.DAG):\n no_dag_found = False\n test_cycle(dag) # Throws if a task cycle is found.\n\n if no_dag_found:\n raise AssertionError(\"module does not contain a valid DAG\")\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=composer)."]]