-
Notifications
You must be signed in to change notification settings - Fork 10
Improve make_group/make_acc_group fixture consistency
#50
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
Conversation
|
This PR breaks backwards compatibility for databrickslabs/blueprint downstream. See build logs for more details. Running from downstreams #46 |
|
✅ 35/35 passed, 3 skipped, 2m30s total Running from acceptance #87 |
I don't fully understand why this check is failing…? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some nits, otherwise looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't modify a global variable - this will break unit tests at multi-threaded execution.
| try: | ||
| yield | ||
| finally: | ||
| _FIXTURES.reset(token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this modifies shared global state and will definitely break when running in multiple threads. why is this necessary? revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need this because the default auto-mocks don't allow the double-check waiting inside make_group() to complete: the return values of .create() and .list() on the (account-)groups REST APIs need to be controlled.
At the moment I don't see a test-specific way to pre-configure the mocks that call_stateful() will set up as fixtures for the fixture being tested. (I didn't find any other unit tests that need this, but may have missed it or there's another path to the same thing.)
Given that pre-configuring mocks for something under test is a fairly common thing to do, I came up with this. It's specifically intended to not only be thread-safe but also async-safe: I don't understand why it will break when running in multiple threads?
The main alternatives that spring to mind are:
- Use a specific keyword argument to
call_stateful()for this purpose that isn't passed through to the fixture under test. - Modify the global fixture (inside
CallContext) that all users ofcall_stateful()have available so that it includes the pre-configured mocks that these group-creation tests use. This would be in the same way asmake_random(for example) is handled.
Do you have a preference, or is there something else I've overlooked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do it without changing a global variable - modify call_context right above the result = ctx[some.__name__](**kwargs) (the first alternative)
def apply(ctx: CallContext):
mock_group = Group(id="an_id")
ctx['ws].groups.create.return_value = mock_group
ctx['ws].groups.list.return_value = [mock_group]
ctx, group = call_stateful(make_group, call_context_callback=apply)| try: | ||
| yield | ||
| finally: | ||
| _FIXTURES.reset(token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do it without changing a global variable - modify call_context right above the result = ctx[some.__name__](**kwargs) (the first alternative)
def apply(ctx: CallContext):
mock_group = Group(id="an_id")
ctx['ws].groups.create.return_value = mock_group
ctx['ws].groups.list.return_value = [mock_group]
ctx, group = call_stateful(make_group, call_context_callback=apply)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* Fixed PyPI metadata ([#54](#54)). In this commit, the PyPI metadata for the pytester project has been updated with the new repository location at <https://github.com/databrickslabs/pytester>. The URLs for issues and source have been changed to point to the new repository, with the `issues` URL now directing to <https://github.com/databrickslabs/pytester/issues> and the `source` URL to <https://github.com/databrickslabs/pytester>. Furthermore, the versioning tool `hatch` has been configured to manage the version number in the "src/databricks/labs/pytester/__about__.py" file. This ensures accurate and consistent versioning for the pytester project moving forward. * Improve `make_group`/`make_acc_group` fixture consistency ([#50](#50)). This PR introduces improvements to the `make_group` and `make_acc_group` fixtures, designed for managing Databricks workspace groups. The enhancements include a double-check approach to ensure group visibility by requiring the group to be retrievable via both `.get()` and `.list()` calls. This mitigates, but does not entirely eliminate, consistency issues with the APIs used for managing groups. The `wait_for_provisioning` argument has been removed and replaced with an internal wait mechanism. The argument is still accepted but triggers a deprecation warning. Internal unit-test plumbing has been updated to use mock fixtures tailored for each test, ensuring double-check implementation testability. New and updated unit tests are included in the `test_iam.py` file, along with the introduction of the `_setup_groups_api` function, which mocks specific clients to ensure group visibility when created. These changes improve consistency and reliability when working with Databricks workspace groups, making it easier for users to adopt the project.
* Fixed PyPI metadata ([#54](#54)). In this commit, the PyPI metadata for the pytester project has been updated with the new repository location at <https://github.com/databrickslabs/pytester>. The URLs for issues and source have been changed to point to the new repository, with the `issues` URL now directing to <https://github.com/databrickslabs/pytester/issues> and the `source` URL to <https://github.com/databrickslabs/pytester>. Furthermore, the versioning tool `hatch` has been configured to manage the version number in the "src/databricks/labs/pytester/__about__.py" file. This ensures accurate and consistent versioning for the pytester project moving forward. * Improve `make_group`/`make_acc_group` fixture consistency ([#50](#50)). This PR introduces improvements to the `make_group` and `make_acc_group` fixtures, designed for managing Databricks workspace groups. The enhancements include a double-check approach to ensure group visibility by requiring the group to be retrievable via both `.get()` and `.list()` calls. This mitigates, but does not entirely eliminate, consistency issues with the APIs used for managing groups. The `wait_for_provisioning` argument has been removed and replaced with an internal wait mechanism. The argument is still accepted but triggers a deprecation warning. Internal unit-test plumbing has been updated to use mock fixtures tailored for each test, ensuring double-check implementation testability. New and updated unit tests are included in the `test_iam.py` file, along with the introduction of the `_setup_groups_api` function, which mocks specific clients to ensure group visibility when created. These changes improve consistency and reliability when working with Databricks workspace groups, making it easier for users to adopt the project.
Changes
This PR implements some fixture improvements that were originally implemented downstream:
.get()and.list()calls. This double-check approach mitigates (but doesn't completely eliminate) problems with consistency of the APIs for working with groups.wait_for_provisioningargument to themake_groupandmake_acc_grouphas now been removed: we always wait. (For compatibility the argument is still accepted but will trigger a deprecation warning.)An incidental change is the internal unit-test plumbing can now be provided with mock fixtures specific to the test; this is needed to ensure the double-check implementation can be tested from the unit tests.
Linked issues
Supersedes databrickslabs/ucx#2634.
Tests