|
16 | 16 | # under the License. |
17 | 17 | from __future__ import annotations |
18 | 18 |
|
| 19 | +import os |
19 | 20 | import subprocess |
20 | 21 | import sys |
| 22 | +from textwrap import dedent |
21 | 23 |
|
22 | | -import pytest |
23 | 24 |
|
24 | | - |
25 | | -@pytest.mark.parametrize( |
26 | | - "create_instance", |
27 | | - [ |
28 | | - "from airflow.api_fastapi.execution_api.in_process import InProcessExecutionAPI; " |
29 | | - "api = InProcessExecutionAPI(); ", |
30 | | - "from airflow.dag_processing.manager import DagFileProcessorManager; " |
31 | | - "manager = DagFileProcessorManager(max_runs=1); ", |
32 | | - ], |
33 | | - ids=["in_process_api", "dag_processor_manager"], |
34 | | -) |
35 | | -def test_construction_defers_execution_api_imports(create_instance): |
| 25 | +def test_construction_defers_execution_api_imports(): |
36 | 26 | result = subprocess.run( |
37 | 27 | [ |
38 | 28 | sys.executable, |
39 | 29 | "-c", |
40 | | - "import sys; " + create_instance + "modules = {'svcs', 'cadwyn', 'fastapi', 'aiohttp', " |
41 | | - "'airflow.api_fastapi.execution_api.app'}; " |
42 | | - "loaded = modules.intersection(sys.modules); " |
43 | | - "assert not loaded, f'{loaded} imported eagerly'", |
| 30 | + dedent(""" |
| 31 | + import sys |
| 32 | +
|
| 33 | + modules = {'svcs', 'cadwyn', 'fastapi', 'aiohttp', 'airflow.api_fastapi.execution_api.app'} |
| 34 | +
|
| 35 | + from airflow.api_fastapi.execution_api.in_process import InProcessExecutionAPI |
| 36 | +
|
| 37 | + api = InProcessExecutionAPI() |
| 38 | + loaded = modules.intersection(sys.modules) |
| 39 | + assert not loaded, f'{loaded} imported eagerly by InProcessExecutionAPI' |
| 40 | +
|
| 41 | + from airflow.dag_processing.manager import DagFileProcessorManager |
| 42 | +
|
| 43 | + manager = DagFileProcessorManager(max_runs=1) |
| 44 | + loaded = modules.intersection(sys.modules) |
| 45 | + assert not loaded, f'{loaded} imported eagerly by DagFileProcessorManager' |
| 46 | + """), |
44 | 47 | ], |
| 48 | + env={**os.environ, "_AIRFLOW__AS_LIBRARY": "1"}, |
45 | 49 | capture_output=True, |
46 | 50 | text=True, |
47 | 51 | check=False, |
|
0 commit comments