From 6b2fca5d49192fdc1a0cdcafa7e15b5279c2be9b Mon Sep 17 00:00:00 2001 From: eakmanrq <6326532+eakmanrq@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:25:51 -0700 Subject: [PATCH] chore: debug flaky test --- tests/cli/test_cli.py | 37 ++++++++++++------------------------- tests/conftest.py | 2 +- tests/dbt/test_model.py | 8 ++++++-- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index d2df451fef..480d186fa1 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -1,10 +1,8 @@ import json -import logging import os import pytest import string import time_machine -from contextlib import contextmanager from os import getcwd, path, remove from pathlib import Path from shutil import rmtree @@ -35,15 +33,6 @@ def runner() -> CliRunner: return CliRunner(env={"COLUMNS": "80"}) -@contextmanager -def disable_logging(): - logging.disable(logging.CRITICAL) - try: - yield - finally: - logging.disable(logging.NOTSET) - - def create_example_project(temp_dir, template=ProjectTemplate.DEFAULT) -> None: """ Sets up CLI tests requiring a real SQLMesh project by: @@ -795,8 +784,7 @@ def test_run_cron_not_elapsed(runner, tmp_path, caplog): init_prod_and_backfill(runner, tmp_path) # No error if `prod` environment exists and cron has not elapsed - with disable_logging(): - result = runner.invoke(cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "run"]) + result = runner.invoke(cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "run"]) assert result.exit_code == 0 assert ( @@ -843,18 +831,17 @@ def test_table_name(runner, tmp_path): # Create and backfill `prod` environment create_example_project(tmp_path) init_prod_and_backfill(runner, tmp_path) - with disable_logging(): - result = runner.invoke( - cli, - [ - "--log-file-dir", - tmp_path, - "--paths", - tmp_path, - "table_name", - "sqlmesh_example.full_model", - ], - ) + result = runner.invoke( + cli, + [ + "--log-file-dir", + tmp_path, + "--paths", + tmp_path, + "table_name", + "sqlmesh_example.full_model", + ], + ) assert result.exit_code == 0 assert result.output.startswith("db.sqlmesh__sqlmesh_example.sqlmesh_example__full_model__") diff --git a/tests/conftest.py b/tests/conftest.py index e76588ffe2..b18271465d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -247,7 +247,7 @@ def rescope_duckdb_classvar(request): yield -@pytest.fixture(scope="module", autouse=True) +@pytest.fixture(scope="function", autouse=True) def rescope_log_handlers(): logging.getLogger().handlers.clear() yield diff --git a/tests/dbt/test_model.py b/tests/dbt/test_model.py index b239015c18..6d100e6aa5 100644 --- a/tests/dbt/test_model.py +++ b/tests/dbt/test_model.py @@ -1,4 +1,6 @@ import datetime +import logging + import pytest from pathlib import Path @@ -275,7 +277,8 @@ def test_load_invalid_ref_audit_constraints( yaml.dump(model_schema, f) assert isinstance(get_console(), NoopConsole) - context = Context(paths=project_dir) + with caplog.at_level(logging.DEBUG): + context = Context(paths=project_dir) assert ( "Skipping audit 'relationships_full_model_cola__cola__ref_not_real_model_' because model 'not_real_model' is not a valid ref" in caplog.text @@ -540,7 +543,8 @@ def test_load_deprecated_incremental_time_column( snapshot_fqn = '"local"."main"."incremental_time_range"' assert isinstance(get_console(), NoopConsole) - context = Context(paths=project_dir) + with caplog.at_level(logging.DEBUG): + context = Context(paths=project_dir) model = context.snapshots[snapshot_fqn].model # Validate model-level attributes assert to_ds(model.start or "") == "2025-01-01"