forked from astronomer/astro-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
28 lines (23 loc) · 845 Bytes
/
conftest.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
import os
import pathlib
import pytest
# Import Operator
import yaml
from airflow.models import Connection, DagRun
from airflow.models import TaskInstance as TI
from airflow.utils.session import create_session
from astro import sql as aql
@pytest.fixture(scope="session", autouse=True)
def create_database_connections():
with open(os.path.dirname(__file__) + "/test-connections.yaml") as file:
yaml_with_env = os.path.expandvars(file.read())
yaml_dicts = yaml.safe_load(yaml_with_env)
connections = []
for i in yaml_dicts["connections"]:
connections.append(Connection(**i))
with create_session() as session:
session.query(DagRun).delete()
session.query(TI).delete()
session.query(Connection).delete()
for conn in connections:
session.add(conn)