-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test_factory_failures.py
95 lines (74 loc) · 2.83 KB
/
test_factory_failures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import uuid
import pytest
from airflow.exceptions import AirflowException
from airflow.utils import timezone
from dagster_airflow.factory import (
make_airflow_dag_containerized_for_handle,
make_airflow_dag_for_handle,
make_airflow_dag_kubernetized_for_handle,
)
from dagster_airflow.test_fixtures import execute_tasks_in_dag
from dagster_airflow_tests.conftest import IMAGE
from dagster import ExecutionTargetHandle
from dagster.utils import load_yaml_from_glob_list, script_relative_path
ENVIRONMENTS_PATH = script_relative_path(
os.path.join(
'..',
'..',
'..',
'.buildkite',
'images',
'docker',
'test_project',
'test_pipelines',
'environments',
)
)
def test_error_dag_python():
pipeline_name = 'demo_error_pipeline'
handle = ExecutionTargetHandle.for_pipeline_module('test_pipelines', pipeline_name)
environment_yaml = [
os.path.join(ENVIRONMENTS_PATH, 'env_filesystem.yaml'),
]
environment_dict = load_yaml_from_glob_list(environment_yaml)
run_id = str(uuid.uuid4())
execution_date = timezone.utcnow()
dag, tasks = make_airflow_dag_for_handle(handle, pipeline_name, environment_dict)
with pytest.raises(AirflowException) as exc_info:
execute_tasks_in_dag(dag, tasks, run_id, execution_date)
assert 'Exception: Unusual error' in str(exc_info.value)
def test_error_dag_containerized():
pipeline_name = 'demo_error_pipeline'
handle = ExecutionTargetHandle.for_pipeline_module('test_pipelines', pipeline_name)
environment_yaml = [
os.path.join(ENVIRONMENTS_PATH, 'env_s3.yaml'),
]
environment_dict = load_yaml_from_glob_list(environment_yaml)
run_id = str(uuid.uuid4())
execution_date = timezone.utcnow()
dag, tasks = make_airflow_dag_containerized_for_handle(
handle, pipeline_name, IMAGE, environment_dict
)
with pytest.raises(AirflowException) as exc_info:
execute_tasks_in_dag(dag, tasks, run_id, execution_date)
assert 'Exception: Unusual error' in str(exc_info.value)
def test_error_dag_k8s():
pipeline_name = 'demo_error_pipeline'
handle = ExecutionTargetHandle.for_pipeline_module('test_pipelines', pipeline_name)
environment_yaml = [
os.path.join(ENVIRONMENTS_PATH, 'env_s3.yaml'),
]
environment_dict = load_yaml_from_glob_list(environment_yaml)
run_id = str(uuid.uuid4())
execution_date = timezone.utcnow()
dag, tasks = make_airflow_dag_kubernetized_for_handle(
handle=handle,
pipeline_name=pipeline_name,
image=IMAGE,
namespace='default',
environment_dict=environment_dict,
)
with pytest.raises(AirflowException) as exc_info:
execute_tasks_in_dag(dag, tasks, run_id, execution_date)
assert 'Exception: Unusual error' in str(exc_info.value)