Skip to content

Commit

Permalink
Update pytest_asyncio.fixture default scope and fix broken registry t…
Browse files Browse the repository at this point in the history
…ests

Summary:
Addressing the pytest warning:
```
/opt/homebrew/Caskroom/miniconda/base/envs/llama-stack/lib/python3.11/site-packages/pytest_asyncio/plugin.py:208: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
```

Details in this discussion
* #699 (comment)


Additional fix:
* Tests were broken after registry.get return type was changed from `List[RoutableObjectWithProvider]` to `Optional[RoutableObjectWithProvider]` in efe791b#diff-5de152bae521b7baef01048a4c0142484f8f1c978a04f3b55f4e4dabc52835beL29

Test Plan:
Run tests
```
pytest llama_stack/distribution/store/tests/test_registry.py -v

collected 6 items

llama_stack/distribution/store/tests/test_registry.py::test_registry_initialization PASSED                                                                                                                     [ 16%]
llama_stack/distribution/store/tests/test_registry.py::test_basic_registration PASSED                                                                                                                          [ 33%]
llama_stack/distribution/store/tests/test_registry.py::test_cached_registry_initialization PASSED                                                                                                              [ 50%]
llama_stack/distribution/store/tests/test_registry.py::test_cached_registry_updates PASSED                                                                                                                     [ 66%]
llama_stack/distribution/store/tests/test_registry.py::test_duplicate_provider_registration PASSED                                                                                                             [ 83%]
llama_stack/distribution/store/tests/test_registry.py::test_get_all_objects PASSED                                                                                                                             [100%]

```
  • Loading branch information
vladimirivic committed Jan 2, 2025
1 parent 49ad168 commit 7b76a60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
42 changes: 19 additions & 23 deletions llama_stack/distribution/store/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
CachedDiskDistributionRegistry,
DiskDistributionRegistry,
)
from llama_stack.providers.utils.kvstore import kvstore_impl, SqliteKVStoreConfig
from llama_stack.providers.utils.kvstore import kvstore_impl
from llama_stack.providers.utils.kvstore.config import SqliteKVStoreConfig


@pytest.fixture
Expand All @@ -26,14 +27,14 @@ def config():
return config


@pytest_asyncio.fixture
@pytest_asyncio.fixture(scope="function")
async def registry(config):
registry = DiskDistributionRegistry(await kvstore_impl(config))
await registry.initialize()
return registry


@pytest_asyncio.fixture
@pytest_asyncio.fixture(scope="function")
async def cached_registry(config):
registry = CachedDiskDistributionRegistry(await kvstore_impl(config))
await registry.initialize()
Expand Down Expand Up @@ -64,8 +65,8 @@ def sample_model():
@pytest.mark.asyncio
async def test_registry_initialization(registry):
# Test empty registry
results = await registry.get("nonexistent", "nonexistent")
assert len(results) == 0
result = await registry.get("nonexistent", "nonexistent")
assert result is None


@pytest.mark.asyncio
Expand All @@ -75,18 +76,16 @@ async def test_basic_registration(registry, sample_bank, sample_model):
print(f"Registering {sample_model}")
await registry.register(sample_model)
print("Getting bank")
results = await registry.get("memory_bank", "test_bank")
assert len(results) == 1
result_bank = results[0]
result_bank = await registry.get("memory_bank", "test_bank")
assert result_bank is not None
assert result_bank.identifier == sample_bank.identifier
assert result_bank.embedding_model == sample_bank.embedding_model
assert result_bank.chunk_size_in_tokens == sample_bank.chunk_size_in_tokens
assert result_bank.overlap_size_in_tokens == sample_bank.overlap_size_in_tokens
assert result_bank.provider_id == sample_bank.provider_id

results = await registry.get("model", "test_model")
assert len(results) == 1
result_model = results[0]
result_model = await registry.get("model", "test_model")
assert result_model is not None
assert result_model.identifier == sample_model.identifier
assert result_model.provider_id == sample_model.provider_id

Expand All @@ -103,9 +102,8 @@ async def test_cached_registry_initialization(config, sample_bank, sample_model)
cached_registry = CachedDiskDistributionRegistry(await kvstore_impl(config))
await cached_registry.initialize()

results = await cached_registry.get("memory_bank", "test_bank")
assert len(results) == 1
result_bank = results[0]
result_bank = await cached_registry.get("memory_bank", "test_bank")
assert result_bank is not None
assert result_bank.identifier == sample_bank.identifier
assert result_bank.embedding_model == sample_bank.embedding_model
assert result_bank.chunk_size_in_tokens == sample_bank.chunk_size_in_tokens
Expand All @@ -129,18 +127,16 @@ async def test_cached_registry_updates(config):
await cached_registry.register(new_bank)

# Verify in cache
results = await cached_registry.get("memory_bank", "test_bank_2")
assert len(results) == 1
result_bank = results[0]
result_bank = await cached_registry.get("memory_bank", "test_bank_2")
assert result_bank is not None
assert result_bank.identifier == new_bank.identifier
assert result_bank.provider_id == new_bank.provider_id

# Verify persisted to disk
new_registry = DiskDistributionRegistry(await kvstore_impl(config))
await new_registry.initialize()
results = await new_registry.get("memory_bank", "test_bank_2")
assert len(results) == 1
result_bank = results[0]
result_bank = await new_registry.get("memory_bank", "test_bank_2")
assert result_bank is not None
assert result_bank.identifier == new_bank.identifier
assert result_bank.provider_id == new_bank.provider_id

Expand Down Expand Up @@ -170,10 +166,10 @@ async def test_duplicate_provider_registration(config):
)
await cached_registry.register(duplicate_bank)

results = await cached_registry.get("memory_bank", "test_bank_2")
assert len(results) == 1 # Still only one result
result = await cached_registry.get("memory_bank", "test_bank_2")
assert result is not None
assert (
results[0].embedding_model == original_bank.embedding_model
result.embedding_model == original_bank.embedding_model
) # Original values preserved


Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"

0 comments on commit 7b76a60

Please sign in to comment.