This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 133cc6174c Fix tests/operators/test_email.py for Database Isolation 
Tests (#41274)
133cc6174c is described below

commit 133cc6174c72a037fc03f560d7d35563b1cfcd97
Author: Jens Scheffler <[email protected]>
AuthorDate: Tue Aug 6 08:42:23 2024 +0200

    Fix tests/operators/test_email.py for Database Isolation Tests (#41274)
---
 tests/operators/test_email.py | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/tests/operators/test_email.py b/tests/operators/test_email.py
index dabafef284..04c4cf7fd8 100644
--- a/tests/operators/test_email.py
+++ b/tests/operators/test_email.py
@@ -22,7 +22,6 @@ from unittest import mock
 
 import pytest
 
-from airflow.models.dag import DAG
 from airflow.operators.email import EmailOperator
 from airflow.utils import timezone
 from tests.test_utils.config import conf_vars
@@ -38,30 +37,24 @@ send_email_test = mock.Mock()
 
 
 class TestEmailOperator:
-    def setup_class(self):
-        self.dag = DAG(
-            "test_dag",
-            default_args={"owner": "airflow", "start_date": DEFAULT_DATE},
-            schedule=INTERVAL,
-        )
-
-    def _run_as_operator(self, **kwargs):
-        task = EmailOperator(
-            to="[email protected]",
-            subject="Test Run",
-            html_content="The quick brown fox jumps over the lazy dog",
-            task_id="task",
-            dag=self.dag,
-            files=["/tmp/Report-A-{{ ds }}.csv"],
-            custom_headers={"Reply-To": "[email protected]"},
-            **kwargs,
-        )
-        task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE)
-        self.dag.clear()
-
-    def test_execute(self):
+    def test_execute(self, dag_maker):
         with conf_vars({("email", "email_backend"): 
"tests.operators.test_email.send_email_test"}):
-            self._run_as_operator()
+            with dag_maker(
+                "test_dag",
+                default_args={"owner": "airflow", "start_date": DEFAULT_DATE},
+                schedule=INTERVAL,
+                serialized=True,
+            ):
+                task = EmailOperator(
+                    to="[email protected]",
+                    subject="Test Run",
+                    html_content="The quick brown fox jumps over the lazy dog",
+                    task_id="task",
+                    files=["/tmp/Report-A-{{ ds }}.csv"],
+                    custom_headers={"Reply-To": "[email protected]"},
+                )
+            dag_maker.create_dagrun()
+            task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE)
         assert send_email_test.call_count == 1
         call_args = send_email_test.call_args.kwargs
         assert call_args["files"] == ["/tmp/Report-A-2016-01-01.csv"]

Reply via email to