Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d8f2402

Browse files
committedOct 28, 2024·
chore(tests): move lazy tokenizer test outside of pytest
1 parent 00fe1f8 commit d8f2402

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed
 

‎scripts/test

+6
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ rye run pytest "$@"
5757

5858
echo "==> Running Pydantic v1 tests"
5959
rye run nox -s test-pydantic-v1 -- "$@"
60+
61+
# this is a separate script instead of a pytest test as we can't rely on the
62+
# execution order, so a tokenizer test could be executed before this check which
63+
# invalidates everything
64+
echo "==> Verifying that \`tokenizers\` is lazily imported"
65+
rye run python -c 'import anthropic, sys; assert "tokenizers" not in sys.modules; print("true")'

‎tests/test_tokenizer.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import asyncio
32
import threading
43
import concurrent.futures
@@ -21,17 +20,6 @@ def _sync_tokenizer_test() -> None:
2120
assert len(encoded_text.ids) == 2 # type: ignore
2221

2322

24-
def test_tokenizers_is_not_imported() -> None:
25-
# note: this test relies on being executed before any of the
26-
# other tests but is a valuable test to avoid issues like this
27-
# https://github.com/anthropics/anthropic-sdk-python/issues/280
28-
assert "tokenizers" not in sys.modules
29-
30-
_sync_tokenizer_test()
31-
32-
assert "tokenizers" in sys.modules
33-
34-
3523
def test_threading() -> None:
3624
failed = False
3725

0 commit comments

Comments
 (0)
Please sign in to comment.