22
22
23
23
import pytest
24
24
25
- from airflow import plugins_manager
26
25
from airflow .exceptions import AirflowConfigException
27
26
from airflow .executors import executor_loader
28
27
from airflow .executors .executor_loader import ConnectorSource , ExecutorLoader , ExecutorName
34
33
35
34
pytestmark = pytest .mark .skip_if_database_isolation_mode
36
35
37
- # Plugin Manager creates new modules, which is difficult to mock, so we use test isolation by a unique name.
38
- TEST_PLUGIN_NAME = "unique_plugin_name_to_avoid_collision_i_love_kitties"
39
-
40
36
41
37
class FakeExecutor :
42
38
is_single_threaded = False
@@ -46,11 +42,6 @@ class FakeSingleThreadedExecutor:
46
42
is_single_threaded = True
47
43
48
44
49
- class FakePlugin (plugins_manager .AirflowPlugin ):
50
- name = TEST_PLUGIN_NAME
51
- executors = [FakeExecutor ]
52
-
53
-
54
45
class TestExecutorLoader :
55
46
def setup_method (self ) -> None :
56
47
from airflow .executors import executor_loader
@@ -89,17 +80,6 @@ def test_should_support_executor_from_core(self, executor_name):
89
80
assert executor .name == ExecutorName (ExecutorLoader .executors [executor_name ], alias = executor_name )
90
81
assert executor .name .connector_source == ConnectorSource .CORE
91
82
92
- @mock .patch ("airflow.plugins_manager.plugins" , [FakePlugin ()])
93
- @mock .patch ("airflow.plugins_manager.executors_modules" , None )
94
- def test_should_support_plugins (self ):
95
- with conf_vars ({("core" , "executor" ): f"{ TEST_PLUGIN_NAME } .FakeExecutor" }):
96
- executor = ExecutorLoader .get_default_executor ()
97
- assert executor is not None
98
- assert "FakeExecutor" == executor .__class__ .__name__
99
- assert executor .name is not None
100
- assert executor .name == ExecutorName (f"{ TEST_PLUGIN_NAME } .FakeExecutor" )
101
- assert executor .name .connector_source == ConnectorSource .PLUGIN
102
-
103
83
def test_should_support_custom_path (self ):
104
84
with conf_vars ({("core" , "executor" ): "tests.executors.test_executor_loader.FakeExecutor" }):
105
85
executor = ExecutorLoader .get_default_executor ()
@@ -124,7 +104,7 @@ def test_should_support_custom_path(self):
124
104
),
125
105
# Core executors and custom module path executor and plugin
126
106
(
127
- f "CeleryExecutor, LocalExecutor, tests.executors.test_executor_loader.FakeExecutor, { TEST_PLUGIN_NAME } .FakeExecutor" ,
107
+ "CeleryExecutor, LocalExecutor, tests.executors.test_executor_loader.FakeExecutor" ,
128
108
[
129
109
ExecutorName (
130
110
"airflow.providers.celery.executors.celery_executor.CeleryExecutor" ,
@@ -138,17 +118,12 @@ def test_should_support_custom_path(self):
138
118
"tests.executors.test_executor_loader.FakeExecutor" ,
139
119
None ,
140
120
),
141
- ExecutorName (
142
- f"{ TEST_PLUGIN_NAME } .FakeExecutor" ,
143
- None ,
144
- ),
145
121
],
146
122
),
147
123
# Core executors and custom module path executor and plugin with aliases
148
124
(
149
125
(
150
- "CeleryExecutor, LocalExecutor, fake_exec:tests.executors.test_executor_loader.FakeExecutor, "
151
- f"plugin_exec:{ TEST_PLUGIN_NAME } .FakeExecutor"
126
+ "CeleryExecutor, LocalExecutor, fake_exec:tests.executors.test_executor_loader.FakeExecutor"
152
127
),
153
128
[
154
129
ExecutorName (
@@ -163,10 +138,6 @@ def test_should_support_custom_path(self):
163
138
"tests.executors.test_executor_loader.FakeExecutor" ,
164
139
"fake_exec" ,
165
140
),
166
- ExecutorName (
167
- f"{ TEST_PLUGIN_NAME } .FakeExecutor" ,
168
- "plugin_exec" ,
169
- ),
170
141
],
171
142
),
172
143
],
@@ -194,8 +165,6 @@ def test_init_executors(self):
194
165
"CeleryExecutor, my.module.path, my.module.path" ,
195
166
"CeleryExecutor, my_alias:my.module.path, my.module.path" ,
196
167
"CeleryExecutor, my_alias:my.module.path, other_alias:my.module.path" ,
197
- f"CeleryExecutor, { TEST_PLUGIN_NAME } .FakeExecutor, { TEST_PLUGIN_NAME } .FakeExecutor" ,
198
- f"my_alias:{ TEST_PLUGIN_NAME } .FakeExecutor, other_alias:{ TEST_PLUGIN_NAME } .FakeExecutor" ,
199
168
],
200
169
)
201
170
def test_get_hybrid_executors_from_config_duplicates_should_fail (self , executor_config ):
@@ -239,21 +208,6 @@ def test_should_support_import_executor_from_core(self, executor_config, expecte
239
208
assert expected_value == executor .__name__
240
209
assert import_source == ConnectorSource .CORE
241
210
242
- @mock .patch ("airflow.plugins_manager.plugins" , [FakePlugin ()])
243
- @mock .patch ("airflow.plugins_manager.executors_modules" , None )
244
- @pytest .mark .parametrize (
245
- ("executor_config" ),
246
- [
247
- (f"{ TEST_PLUGIN_NAME } .FakeExecutor" ),
248
- (f"my_cool_alias:{ TEST_PLUGIN_NAME } .FakeExecutor, CeleryExecutor" ),
249
- ],
250
- )
251
- def test_should_support_import_plugins (self , executor_config ):
252
- with conf_vars ({("core" , "executor" ): executor_config }):
253
- executor , import_source = ExecutorLoader .import_default_executor_cls ()
254
- assert "FakeExecutor" == executor .__name__
255
- assert import_source == ConnectorSource .PLUGIN
256
-
257
211
@pytest .mark .parametrize (
258
212
"executor_config" ,
259
213
[
0 commit comments