Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pytest_asyncio.fixture default scope and fix broken registry tests #707

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vladimirivic
Copy link
Contributor

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

Additional fix:

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%]

…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%]

```
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 2, 2025
@vladimirivic vladimirivic marked this pull request as ready for review January 2, 2025 20:34
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
Copy link
Contributor

@yanxi0830 yanxi0830 Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would be a better practice to avoid this project level event loop config to use @pytest.mark.asyncio(loop_scope="function") for each test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think being explicit with scopes with fixtures is a good practice and we should keep doing it for our fixtures.

I think it should be fine to have this config. It is not so we can avoid setting explicit scopes, but just to have the default scope when the scope is not specified as pytest-asyncio will eventually change it "function" by default - in the end we get the same. This way we only explicitly say it so we don't get the warning telling us our default scope will be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants