From 0c4706658b93b75add742877b19cb4782cf2b120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Tue, 24 Nov 2026 21:00:52 -0600 Subject: [PATCH] Share the platform fixture from the root conftest --- tests/conftest.py | 63 ----------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 7d27f8e..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,63 +0,0 @@ -"""A fresh platform per test, on SQLite and on PostgreSQL, and the way an operator runs it: -save a pipeline, run the `ingest` job (each run in its own process, as Dagster does).""" - -import json -import os -import subprocess -from pathlib import Path -from types import SimpleNamespace - -import pytest -from sqlalchemy import create_engine, make_url, text - - -def run(env, *args): - subprocess.run(args, env=env, check=True) - - -def ingest(env, pipeline="site"): - config = Path(env["ISSSTELEON_DATA"]) / "run.json" - config.write_text(json.dumps({"ops": {"run_pipeline": {"config": {"pipeline": pipeline}}}})) - run(env, "dagster", "job", "execute", "-m", "models.definitions", "-j", "ingest", - "--config", str(config)) # fmt: skip - - -@pytest.fixture(params=["sqlite", "postgres"]) -def platform(request, tmp_path): - """Env for a fresh platform on each backend, and a SQL connection to read it back.""" - (tmp_path / "dagster").mkdir() - env = { - **os.environ, - "ISSSTELEON_DATA": str(tmp_path), - "DLT_DATA_DIR": str(tmp_path / "dlt"), - "DAGSTER_HOME": str(tmp_path / "dagster"), - } - if request.param == "sqlite": - url = env["PLATFORM_DATABASE_URL"] = f"sqlite:///{tmp_path / 'platform.db'}" - attach = [f"ATTACH '{tmp_path}/platform__{s}.db' AS {s}" for s in ("bronze", "silver")] - else: - pg = os.environ["POSTGRES_TEST_URL"] # required: run with `docker compose run --rm test` - env.update(PLATFORM_DATABASE_URL=pg, DBT_TARGET="postgres") - url = make_url(pg).set(drivername="postgresql+psycopg2") - attach = [] - with create_engine(url).begin() as con: - for schema in ("bronze", "silver", "config"): - con.exec_driver_sql(f"drop schema if exists {schema} cascade") - - def count(table: str) -> int: - with create_engine(url).connect() as con: - for statement in attach: - con.exec_driver_sql(statement) - return con.execute(text(f"select count(*) from {table}")).scalar() - - def query(sql: str): - with create_engine(url).connect() as con: - for statement in attach: - con.exec_driver_sql(statement) - return con.execute(text(sql)).fetchall() - - return SimpleNamespace( - env=env, count=count, query=query, - run=lambda *args: run(env, *args), - ingest=lambda pipeline="site": ingest(env, pipeline), - ) # fmt: skip