Sample job test: run each Dagster run in its own process, on SQLite and PostgreSQL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from sqlalchemy import create_engine, make_url, text
|
from sqlalchemy import create_engine, make_url, text
|
||||||
|
|
||||||
from synthetic.hospital import generate
|
|
||||||
|
|
||||||
POSTGRES = os.environ.get("POSTGRES_TEST_URL") # set by CI's postgres job
|
POSTGRES = os.environ.get("POSTGRES_TEST_URL") # set by CI's postgres job
|
||||||
|
HOSPITAL = Path(__file__).parents[2] / "tests" / "fixtures" / "hospital" / "hospital_cacu.db"
|
||||||
|
PATIENTS = 312
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -14,13 +15,13 @@ POSTGRES = os.environ.get("POSTGRES_TEST_URL") # set by CI's postgres job
|
|||||||
["sqlite", pytest.param("postgres", marks=pytest.mark.skipif(not POSTGRES, reason="no PG"))],
|
["sqlite", pytest.param("postgres", marks=pytest.mark.skipif(not POSTGRES, reason="no PG"))],
|
||||||
)
|
)
|
||||||
def test_sample_job_loads_and_reloads_without_duplicates(backend, tmp_path):
|
def test_sample_job_loads_and_reloads_without_duplicates(backend, tmp_path):
|
||||||
generate(tmp_path / "synthetic", seed=7, patients_per_domain=20)
|
|
||||||
(tmp_path / "dagster").mkdir()
|
(tmp_path / "dagster").mkdir()
|
||||||
env = {
|
env = {
|
||||||
**os.environ,
|
**os.environ,
|
||||||
"ISSSTELEON_DATA": str(tmp_path),
|
"ISSSTELEON_DATA": str(tmp_path),
|
||||||
"DLT_DATA_DIR": str(tmp_path / "dlt"),
|
"DLT_DATA_DIR": str(tmp_path / "dlt"),
|
||||||
"DAGSTER_HOME": str(tmp_path / "dagster"),
|
"DAGSTER_HOME": str(tmp_path / "dagster"),
|
||||||
|
"HOSPITAL_CACU_URL": f"sqlite:///{HOSPITAL}",
|
||||||
}
|
}
|
||||||
if backend == "sqlite":
|
if backend == "sqlite":
|
||||||
url = env["PLATFORM_DATABASE_URL"] = f"sqlite:///{tmp_path / 'platform.db'}"
|
url = env["PLATFORM_DATABASE_URL"] = f"sqlite:///{tmp_path / 'platform.db'}"
|
||||||
@@ -43,5 +44,7 @@ def test_sample_job_loads_and_reloads_without_duplicates(backend, tmp_path):
|
|||||||
with create_engine(url).connect() as con:
|
with create_engine(url).connect() as con:
|
||||||
for statement in attach:
|
for statement in attach:
|
||||||
con.exec_driver_sql(statement)
|
con.exec_driver_sql(statement)
|
||||||
assert con.execute(text("select count(*) from bronze.patients")).scalar() == 20
|
assert con.execute(text("select count(*) from bronze.patients")).scalar() == PATIENTS
|
||||||
assert con.execute(text("select count(*) from silver.cacu_patients")).scalar() == 20
|
assert (
|
||||||
|
con.execute(text("select count(*) from silver.cacu_patients")).scalar() == PATIENTS
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user