suii2210 commented on code in PR #58969: URL: https://github.com/apache/airflow/pull/58969#discussion_r2603187476
########## airflow-core/docs/best-practices.rst: ########## @@ -650,6 +650,127 @@ want to optimize your Dags there are the following actions you can take: Testing a Dag ^^^^^^^^^^^^^ + +Testing Operators with pytest +----------------------------- + +The ``dag.test()`` example shown in older documentation works only when executed +inside a DAG file, but often does *not* work inside pytest because DAG +serialization is inactive in standalone test files. + +Below are two recommended, runnable patterns for unit-testing custom operators +with pytest. Both examples work with Airflow 3.x. + +1. Using ``TaskInstance.run()`` +2. Using ``dag.create_dagrun()`` + + +Example: DummySuccessOperator Review Comment: sure I will change this . -- 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]
