Skip to content

Commit e6f455d

Browse files
committed
move the test so it doesn't error so often
1 parent 0fe9b5f commit e6f455d

1 file changed

Lines changed: 37 additions & 35 deletions

File tree

tests/utils/test_metaprogramming.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,42 @@
1919
serialize_env,
2020
)
2121

22+
23+
def test_print_exception(mocker: MockerFixture):
24+
out_mock = mocker.Mock()
25+
26+
test_env = {
27+
"test_fun": Executable(
28+
name="test_func",
29+
payload="""def test_fun():
30+
raise RuntimeError("error")""",
31+
path="/test/path.py",
32+
),
33+
}
34+
env: t.Dict[str, t.Any] = {}
35+
prepare_env(env, test_env)
36+
try:
37+
eval("test_fun()", env)
38+
except Exception as ex:
39+
print_exception(ex, test_env, out_mock)
40+
41+
expected_message = f"""Traceback (most recent call last):
42+
43+
File "{__file__}", line 37, in test_print_exception
44+
eval("test_fun()", env)
45+
46+
File "<string>", line 1, in <module>
47+
48+
File '/test/path.py' (or imported file), line 2, in test_fun
49+
def test_fun():
50+
raise RuntimeError("error")
51+
52+
53+
RuntimeError: error
54+
"""
55+
out_mock.write.assert_called_once_with(expected_message)
56+
57+
2258
X = 1
2359
Y = 2
2460
Z = 3
@@ -114,6 +150,7 @@ def closure(z):
114150

115151
def test_serialize_env_error() -> None:
116152
with pytest.raises(SQLMeshError) as e:
153+
# pretend to be the module pandas
117154
serialize_env({"pandas": pd}, module="pandas")
118155

119156

@@ -188,38 +225,3 @@ def baz(self):
188225
return X + a""",
189226
),
190227
}
191-
192-
193-
def test_print_exception(mocker: MockerFixture):
194-
out_mock = mocker.Mock()
195-
196-
test_env = {
197-
"test_fun": Executable(
198-
name="test_func",
199-
payload="""def test_fun():
200-
raise RuntimeError("error")""",
201-
path="/test/path.py",
202-
),
203-
}
204-
env: t.Dict[str, t.Any] = {}
205-
prepare_env(env, test_env)
206-
try:
207-
eval("test_fun()", env)
208-
except Exception as ex:
209-
print_exception(ex, test_env, out_mock)
210-
211-
expected_message = f"""Traceback (most recent call last):
212-
213-
File "{__file__}", line 200, in test_print_exception
214-
eval("test_fun()", env)
215-
216-
File "<string>", line 1, in <module>
217-
218-
File '/test/path.py' (or imported file), line 2, in test_fun
219-
def test_fun():
220-
raise RuntimeError("error")
221-
222-
223-
RuntimeError: error
224-
"""
225-
out_mock.write.assert_called_once_with(expected_message)

0 commit comments

Comments
 (0)