Skip to content

Commit 2d13c2f

Browse files
Fix: Adapt test to use thread specific consoles (#5414)
1 parent 88a3679 commit 2d13c2f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/core/test_integration.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
import pytest
1515
from pytest import MonkeyPatch
1616
from pathlib import Path
17-
from sqlmesh.core.console import set_console, get_console, TerminalConsole, CaptureTerminalConsole
17+
from sqlmesh.core.console import (
18+
MarkdownConsole,
19+
set_console,
20+
get_console,
21+
TerminalConsole,
22+
CaptureTerminalConsole,
23+
)
1824
from sqlmesh.core.config.naming import NameInferenceConfig
1925
from sqlmesh.core.model.common import ParsableSql
2026
from sqlmesh.utils.concurrency import NodeExecutionFailedError
@@ -10589,9 +10595,16 @@ def entrypoint(evaluator: MacroEvaluator) -> str:
1058910595
new_model_a_snapshot_id = list(plan.modified_snapshots)[0]
1059010596

1059110597
# now, trigger a prod restatement plan in a different thread and block it to simulate a long restatement
10598+
thread_console = None
10599+
1059210600
def _run_restatement_plan(tmp_path: Path, config: Config, q: queue.Queue):
10601+
nonlocal thread_console
1059310602
q.put("thread_started")
1059410603

10604+
# Give this thread its own markdown console to avoid Rich LiveError
10605+
thread_console = MarkdownConsole()
10606+
set_console(thread_console)
10607+
1059510608
# give this thread its own Context object to prevent segfaulting the Python interpreter
1059610609
restatement_ctx = Context(paths=[tmp_path], config=config)
1059710610

@@ -10647,7 +10660,7 @@ def _run_restatement_plan(tmp_path: Path, config: Config, q: queue.Queue):
1064710660
assert isinstance(plan_error, ConflictingPlanError)
1064810661
assert "please re-apply your plan" in repr(plan_error).lower()
1064910662

10650-
output = " ".join(re.split("\s+", console.captured_output, flags=re.UNICODE))
10663+
output = " ".join(re.split("\\s+", thread_console.captured_output, flags=re.UNICODE)) # type: ignore
1065110664
assert (
1065210665
f"The following models had new versions deployed while data was being restated: └── test.model_a"
1065310666
in output

0 commit comments

Comments
 (0)