Skip to content

Commit 131ab91

Browse files
use find_spec to see if lark resolves
1 parent 307b011 commit 131ab91

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

tests/test_tools.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.util
12
import json
23
import re
34
from dataclasses import dataclass, replace
@@ -35,13 +36,6 @@
3536

3637
from .conftest import IsDatetime, IsStr
3738

38-
try:
39-
import lark
40-
except ImportError:
41-
lark_installed = False
42-
else:
43-
lark_installed = True
44-
4539

4640
def test_tool_no_ctx():
4741
agent = Agent(TestModel())
@@ -1489,14 +1483,14 @@ def test_function_text_format_regex_invalid():
14891483
FunctionTextFormat(syntax='regex', grammar='[')
14901484

14911485

1492-
@pytest.mark.skipif(not lark_installed, reason='lark not installed')
1486+
@pytest.mark.skipif(not importlib.util.find_spec('lark'), reason='lark not installed')
14931487
def test_function_text_format_lark_valid():
14941488
format = FunctionTextFormat(syntax='lark', grammar='start: "hello"')
14951489
assert format.syntax == 'lark'
14961490
assert format.grammar == 'start: "hello"'
14971491

14981492

1499-
@pytest.mark.skipif(not lark_installed, reason='lark not installed')
1493+
@pytest.mark.skipif(not importlib.util.find_spec('lark'), reason='lark not installed')
15001494
def test_function_text_format_lark_invalid():
15011495
with pytest.raises(ValueError, match='Lark grammar is invalid'):
15021496
FunctionTextFormat(syntax='lark', grammar='invalid grammar [')

0 commit comments

Comments
 (0)