Skip to content

Commit 29a586a

Browse files
committed
Refactor test environment setup by introducing setup_duckdb_env function for improved clarity and reusability
1 parent 21350f2 commit 29a586a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

tests/cli_helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ def set_cli_env(
2929
monkeypatch.setenv("SQLCOMPARE_CONN_DEFAULT", connection_name)
3030
monkeypatch.setenv(f"SQLCOMPARE_CONN_{connection_name.upper()}", connection_url)
3131
monkeypatch.setenv("SQLCOMPARE_COMPARISON_SCHEMA", schema)
32+
33+
34+
def setup_duckdb_env(monkeypatch, config_dir: Path, schema: str = "sqlcompare") -> None:
35+
"""Setup environment for DuckDB tests without a specific connection."""
36+
monkeypatch.setenv("SQLCOMPARE_CONFIG_DIR", str(config_dir))
37+
monkeypatch.setenv("SQLCOMPARE_COMPARISON_SCHEMA", schema)

tests/test_cli_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sqlcompare.cli import app
1010
from sqlcompare.config import load_test_runs
1111
from sqlcompare.db import DBConnection
12+
from tests.cli_helpers import setup_duckdb_env
1213

1314

1415
def _seed_duckdb(db_path: Path) -> None:
@@ -124,7 +125,7 @@ def test_dataset_command_with_yaml_dataset(tmp_path: Path, monkeypatch) -> None:
124125
def test_dataset_command_file_name_without_connection(
125126
tmp_path: Path, monkeypatch
126127
) -> None:
127-
monkeypatch.setenv("SQLCOMPARE_CONFIG_DIR", str(tmp_path / "config"))
128+
setup_duckdb_env(monkeypatch, tmp_path / "config")
128129

129130
runner = CliRunner()
130131
dataset_path = Path(__file__).parent / "datasets" / "row_compare" / "dataset.yaml"

tests/test_cli_table.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from sqlcompare.cli import app
88
from sqlcompare.config import load_test_runs
9-
from tests.cli_helpers import seed_duckdb, set_cli_env
9+
from tests.cli_helpers import seed_duckdb, set_cli_env, setup_duckdb_env
1010

1111

1212
def test_table_command_with_options(tmp_path, monkeypatch) -> None:
@@ -43,8 +43,7 @@ def test_table_command_with_options(tmp_path, monkeypatch) -> None:
4343

4444

4545
def test_table_command_with_files(tmp_path, monkeypatch) -> None:
46-
config_dir = tmp_path / "config"
47-
monkeypatch.setenv("SQLCOMPARE_CONFIG_DIR", str(config_dir))
46+
setup_duckdb_env(monkeypatch, tmp_path / "config")
4847
runner = CliRunner()
4948

5049
dataset_dir = Path(__file__).parent / "datasets" / "row_compare"

0 commit comments

Comments
 (0)