Skip to content

Commit

Permalink
chore(tests): move lazy tokenizer test outside of pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Oct 28, 2024
1 parent 00fe1f8 commit d8f2402
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 6 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ rye run pytest "$@"

echo "==> Running Pydantic v1 tests"
rye run nox -s test-pydantic-v1 -- "$@"

# this is a separate script instead of a pytest test as we can't rely on the
# execution order, so a tokenizer test could be executed before this check which
# invalidates everything
echo "==> Verifying that \`tokenizers\` is lazily imported"
rye run python -c 'import anthropic, sys; assert "tokenizers" not in sys.modules; print("true")'
12 changes: 0 additions & 12 deletions tests/test_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import asyncio
import threading
import concurrent.futures
Expand All @@ -21,17 +20,6 @@ def _sync_tokenizer_test() -> None:
assert len(encoded_text.ids) == 2 # type: ignore


def test_tokenizers_is_not_imported() -> None:
# note: this test relies on being executed before any of the
# other tests but is a valuable test to avoid issues like this
# https://github.com/anthropics/anthropic-sdk-python/issues/280
assert "tokenizers" not in sys.modules

_sync_tokenizer_test()

assert "tokenizers" in sys.modules


def test_threading() -> None:
failed = False

Expand Down

0 comments on commit d8f2402

Please sign in to comment.