Closed nfx closed 1 month ago
This PR breaks backwards compatibility for databrickslabs/lsql downstream. See build logs for more details.
Running from downstreams #5
This PR breaks backwards compatibility for databrickslabs/blueprint downstream. See build logs for more details.
Running from downstreams #5
❌ 26/27 passed, 1 failed, 3 skipped, 2m7s total
Running from acceptance #45
spark
has been added to the codebase, providing a Databricks Connect Spark session for testing purposes. The fixture requires thedatabricks-connect
package to be installed and takes aWorkspaceClient
object as an argument. It first checks if acluster_id
is present in the environment, and if not, it skips the test and raises a message. The fixture then ensures that the cluster is running and attempts to import theDatabricksSession
class from thedatabricks.connect
module. If the import fails, it skips the test and raises a message. This new fixture enables easier testing of Databricks Connect functionality, reducing boilerplate code required to set up a Spark session within tests. Additionally, a newis_in_debug
fixture has been added, although there is no further documentation or usage examples provided for it.make_*_permissions
fixtures. In this release, we have added new fixtures to the pytester plugin for managing permissions in Databricks. These fixtures includemake_alert_permissions
,make_authorization_permissions
,make_cluster_permissions
,make_cluster_policy_permissions
,make_dashboard_permissions
,make_directory_permissions
,make_instance_pool_permissions
,make_job_permissions
,make_notebook_permissions
,make_pipeline_permissions
,make_query_permissions
,make_registered_model_permissions
,make_repository_permissions
,make_serving_endpoint_permissions
,make_warehouse_permissions
,make_workspace_file_permissions
, andmake_workspace_file_path_permissions
. These fixtures allow for easier testing of functionality that requires managing permissions in Databricks, and are used for managing permissions for various Databricks resources such as alerts, authorization, clusters, cluster policies, dashboards, directories, instance pools, jobs, notebooks, pipelines, queries, registered models, repositories, serving endpoints, warehouses, and workspace files. Additionally, a newmake_notebook_permissions
fixture has been introduced in thetest_permissions.py
file for integration tests, which allows for more comprehensive testing of the IAM system's behavior when handling notebook permissions.make_catalog
fixture. A new fixture,make_catalog
, has been added to the codebase to facilitate testing with specific catalogs, ensuring isolation and reproducibility. This fixture creates a catalog, returns its information, and removes the catalog after the test is complete. It can be used in conjunction with other fixtures such asws
,sql_backend
, andmake_random
. The fixture is utilized in the updatedtest_catalog_fixture
integration test function, which now includes new argumentsmake_catalog
,make_schema
, andmake_table
. These fixtures create catalog, schema, and table objects, enabling more comprehensive testing of the catalog, schema, and table creation functionality. Please note that catalogs created using this fixture are not currently protected from being deleted by the watchdog.make_catalog
,make_schema
, andmake_table
fixtures (#33). In this release, we have updated thedatabricks-labs-blueprint
package dependency todatabricks-labs-lsql~=0.10
and added several fixtures to the codebase to improve the reliability and maintainability of the test suite. We have introduced three new fixturesmake_catalog
,make_schema
, andmake_table
that are used for creating and managing test catalogs, schemas, and tables, respectively. These fixtures enable the creation of arbitrary test data and simplify testing by allowing predictable and consistent setup and teardown of test data for integration tests. Additionally, we have added several debugging fixtures, includingdebug_env_name
,debug_env
,env_or_skip
, andsql_backend
, to aid in testing DataBricks features related to SQL, environments, and more. Themake_udf
fixture has also been added for testing user-defined functions in DataBricks. These new fixtures and methods will assist in testing the project's functionality and ensure that the code is working as intended, making the tests more maintainable and easier to understand.make_cluster
documentation. Themake_cluster
fixture has been updated with new functionality and improvements. It now creates a Databricks cluster with specified configurations, waits for it to start, and cleans it up after the test, returning a function to create clusters. Thecluster_id
attribute is accessible from the returned object. The fixture accepts several keyword arguments:single_node
to create a single-node cluster,cluster_name
to specify a cluster name,spark_version
to set the Spark version, andautotermination_minutes
to determine when the cluster should be automatically terminated. Thews
andmake_random
parameters have been removed. The commit also introduces a new test function,test_cluster
, that creates a single-node cluster and outputs a message indicating the creation. Documentation for themake_cluster
function has been added, and themake_cluster_policy
function remains unchanged.make_experiment
fixture. In this release, we introduce themake_experiment
fixture in thedatabricks.labs.pytester.fixtures.ml
module, facilitating the creation and cleanup of Databricks Experiments for testing purposes. This fixture accepts optionalpath
andexperiment_name
parameters and returns adatabricks.sdk.service.ml.CreateExperimentResponse
object. Additionally,make_experiment_permissions
has been added for managing experiment permissions. In thepermissions.py
file, the_make_permissions_factory
function replaces the previous_make_redash_permissions_factory
, enhancing the code's maintainability and extensibility. Furthermore, amake_experiment
fixture has been added to theplugin.py
file for creating experiments with custom names and descriptions. Lastly, atest_experiments
function has been included in thetests/integration/fixtures
directory, utilizingmake_group
,make_experiment
, andmake_experiment_permissions
fixtures to create experiments and assign group permissions.make_instance_pool
documentation. In this release, themake_instance_pool
fixture has been updated with added documentation, and the usage example has been slightly modified. The fixture now accepts optional keyword arguments for the instance pool name and node type ID, with default values set for each. Themake_random
fixture is still required for generating unique names. Additionally, a new function,log_workspace_link
, has been updated to accept a new parameteranchor
for controlling the inclusion of an anchor (#
) in the generated URL. New test functionstest_instance_pool
andtest_cluster_policy
have been added to enhance the integration testing of the compute system, providing more comprehensive coverage for instance pools and cluster policies. Furthermore, documentation has been added for themake_instance_pool
fixture. Lastly, three test functions,test_cluster
,test_instance_pool
, andtest_job
, have been removed, but the setup functions for these tests are retained, indicating a possible streamlining of the codebase.make_job
documentation. Themake_job
fixture has been updated with additional arguments and improved documentation. It now acceptsnotebook_path
,name
,spark_conf
, andlibraries
as optional keyword arguments, and can accept any additional arguments to be passed to theWorkspaceClient.jobs.create
method. If nonotebook_path
ortasks
argument is provided, a random notebook is created and a single task with a notebook task is run using the latest Spark version and a single worker cluster. The fixture has been improved to manage Databricks jobs and clean them up after testing. Additionally, documentation has been added for themake_job
function and thetest_job
function in the test fixtures file. Thetest_job
function, which created a job and logged its creation, has been removed, and thetest_cluster
andtest_pipeline
functions remain unchanged. Theos
module is no longer imported in this file.make_model
fixture. A new pytest fixture,make_model
, has been added to the codebase for the open-source library. This fixture facilitates the creation and automatic cleanup of Databricks Models during tests, returning aGetModelResponse
object. The optionalmodel_name
parameter allows for customization, with a default value ofdummy-*
. Themake_model
fixture can be utilized in conjunction with other fixtures such asws
,make_random
, andmake_registered_model_permissions
, streamlining the testing of model-related functionality. Additionally, a new test function,test_models
, has been introduced, utilizingmake_model
,make_group
, andmake_registered_model_permissions
fixtures to test model management within the system. This new feature enhances the library's testing capabilities, making it easier to create, configure, and manage models and related resources during test execution.make_pipeline
fixture. A new fixture namedmake_pipeline
has been added to the project, which facilitates the creation and cleanup of a Delta Live Tables Pipeline after testing. This fixture is added to thecompute.py
file and takes optional keyword arguments such asname
,libraries
, andclusters
. It generates a random name, creates a disposable notebook with random libraries, and creates a single node cluster with 16GB memory and local disk if these arguments are not provided. The fixture returns a function to create pipelines, resulting in aCreatePipelineResponse
instance. Additionally, a new integration test has been added to test the functionality of this fixture, and it logs information about the created pipeline for debugging and inspection purposes. This new fixture improves the testing capabilities of the project, allowing for more robust and flexible tests of pipeline creation and management.make_query
fixture. In this release, we have added a new fixture calledmake_query
to the plugin module for the Redash integration. This fixture creates aLegacyQuery
object for testing query-related functionality in a controlled environment. It can be used in conjunction with themake_user
andmake_query_permissions
fixtures to test query permissions for a specific user. Themake_query
fixture generates a random query name, creates a table, and uses thews.queries_legacy.create
method to create the query. The query is then deleted using thews.queries_legacy.delete
method after the test is completed. This fixture is utilized in thetest_permissions_for_redash
function, which creates a user and a query, and then sets the permission level for the query for the created user using themake_query_permissions
fixture. This enhancement improves the testing capabilities of the Pytester framework for projects that utilize Redash.make_schema
fixture. A newmake_schema
fixture has been added to the open-source library to improve schema management and testing. This fixture creates a schema with an optional catalog name and a schema name, which defaults to a random string. The fixture cleans up the schema after the test is complete and returns an instance ofSchemaInfo
. It can be used in conjunction with other fixtures such asmake_table
andmake_udf
for easier testing and setup of schemas. Additionally, themake_schema
fixture includes a new keyword-only argumentlog_workspace_link
to log a link to the created schema in the Databricks workspace. Themake_catalog
fixture has also been updated to include thelog_workspace_link
argument for logging links to created catalogs. These changes enhance the testability of the code and provide better catalog and schema management in the Databricks workspace.make_serving_endpoint
fixture. A newmake_serving_endpoint
fixture has been added to the codebase, located inbaseline.py
,ml.py
, andplugin.py
files, andtests/integration/fixtures/test_ml.py
. This fixture enables the creation and deletion of Databricks Serving Endpoints, handling any potential DatabricksError exceptions during teardown. It also creates a model for a small workload size and returns aServingEndpointDetailed
object. Themake_serving_endpoint_permissions
fixture is introduced as well, creating serving endpoint permissions for a specified object ID, permission level, and group name. New tests have been implemented to demonstrate the usage of these fixtures, showing how to create serving endpoints, grant query permissions to a group, and test the endpoint. Additionally, updates have been made to the README.md file to include documentation for the new fixtures.make_storage_credential
fixture. In this release, we have added a new fixture calledmake_storage_credential
to our testing utilities. This fixture creates a storage credential with configurable parameters such as credential name, Azure service principal information, AWS IAM role ARN, and read-only status. It can be used to create either an Azure or AWS storage credential, depending on the provided parameters, and removes the created credential after the test. This fixture is implemented inplugin.py
and is added to the existing list of fixtures for consistent and easy-to-use testing setup. Additionally, we have introduced an integration test calledtest_storage_credential
in the test catalog for fixtures. This test utilizes the newmake_storage_credential
fixture and verifies the functionality of creating a storage credential and the integration between the system and storage services. These new additions will make it easier to write tests that require access to storage resources and improve the efficiency and ease of testing and developing new features in the codebase.make_table
fixture. In this release, we've added themake_table
fixture to simplify testing operations on tables and catalogs. This fixture creates a table with a given catalog and schema name, CTAS statement, and properties. It can create the table as a non-delta or delta table, external table with CSV or Delta location, or a view, and allows overriding the storage location. Additionally, we've updated the fixture to include new parameters and functionality, such as logging a workspace link for the created table and specifying the catalog and schema where the table will be created. The fixture now also includes new functions for creating and casting columns in the table. After the test, the fixture automatically removes the created table. This release aims to provide a more customizable and convenient way to test table operations.make_udf
fixture. Themake_udf
fixture has been added to facilitate the creation and removal of User-Defined Functions (UDFs) for testing purposes. This fixture creates a UDF with optional parameters to specify catalog, schema, name, and Hive UDF creation. It returns an instance ofdatabricks.sdk.service.catalog.FunctionInfo
. The UDF is removed after the test. This feature is utilized in the newtest_make_some_udfs
integration test, where it creates two UDFs in a schema within the Hive metastore, one with and one without Hive support. Additionally, thetest_create_view
test is now skipped, and thetest_table_fixture
test remains unchanged. This change improves the ability to test UDFs within the Hive metastore, and allows for more comprehensive testing by creating UDFs programmatically.make_warehouse
fixture. A newmake_warehouse
fixture has been added to the test suite, which allows for the creation and customization of a Databricks warehouse for testing purposes. The fixture accepts optional keyword arguments such aswarehouse_name
,warehouse_type
,cluster_size
,max_num_clusters
, andenable_serverless_compute
, allowing users to configure the warehouse's properties. It returns a function that creates a warehouse using the provided parameters and handles cleanup after the test is complete. Additionally, a corresponding test functiontest_warehouse_has_remove_after_tag
has been added to verify that a newly created warehouse has the expectedRemoveAfter
tag, facilitating automated testing and resource management. This enhancement expands the testing capabilities of the plugin and provides a more streamlined approach to testing functionality related to Databricks warehouses.make_query
. Themake_query
fixture has been updated to allow for greater customization in testing, with the addition of a newquery
keyword argument. This parameter enables users to specify a custom SQL query to be stored and executed, with the default value beingSELECT * FROM <newly created random table>
. The fixture continues to create and remove theLegacyQuery
object, making it user-friendly. With this enhancement, users have increased flexibility to tailor their tests to specific needs, providing more targeted and precise testing outcomes.make_cluster_policy
. In this release, we introduce new features to enhance testing and managing Databricks cluster policies and workspace link logging in your project. We've added themake_cluster_policy
fixture, which simplifies the creation and deletion of cluster policies using a specified workspace. This fixture returns aCreatePolicyResponse
instance and can be used within test functions. Additionally, we've developed thelog_workspace_link
fixture, which constructs and logs a workspace link for debugging and tracking purposes. Themake_cluster_policy
function is also introduced in theplugin.py
file, enabling users to manage and test Databricks cluster policies using the pytester framework. To ensure proper functionality, thetest_compute.py
file includes a test function formake_cluster_policy
. These improvements will help streamline testing processes and enhance the overall user experience.make_group
andmake_user
. In this release, we have introduced themake_group
andmake_user
fixtures to manage Databricks workspace groups and users, respectively. Themake_group
fixture allows you to create groups with specified members, roles, and entitlements, handling eventual consistency issues and waiting for group provisioning if required. Themake_user
fixture creates a user and deletes it after the test, handling naming conflicts by retrying the creation process for 30 seconds. Both fixtures return instances ofGroup
andUser
, respectively, and have been documented in the README.md with usage examples. Additionally, we have introduced a built-in logger that traces entity creation and deletion through links in the Databricks Workspace UI, and added documentation for themake_group
andmake_user
functions using thegen-readme.py
script. The release also includes updates to theconftest.py
file in thetests/integration
directory, importing thefixture
function frompytest
and theinstall_logger
andlogging
modules fromdatabricks.labs.blueprint.logger
to improve documentation and configure logging for the project.make_notebook
,make_directory
, andmake_repo
. Themake_notebook
,make_directory
, andmake_repo
fixtures have been updated with new functionality and improved documentation in this release. These fixtures are used in tests to manage Databricks notebooks, directories, and repos respectively, and they now return functions that create resources with specified parameters. Themake_notebook
fixture now includes optional keyword arguments forpath
,content
,language
,format
, andoverwrite
, and returns anos.PathLike
object that will be automatically deleted after the test is complete. Themake_directory
fixture now includes an optional keyword argument forpath
, and themake_repo
fixture now includes optional keyword arguments forurl
,provider
, andpath
. These fixtures simplify the process of creating and managing Databricks resources in tests and help ensure that resources are properly cleaned up after each test is complete. The commit also includes documentation for the new functionality and integration tests for these fixtures.make_secret_scope
andmake_secret_scope_acl
. In this release, documentation has been added for two new functions,make_secret_scope
andmake_secret_scope_acl
, which are used for creating and managing secret scopes and their associated access control lists (ACLs) in a Databricks Workspace. Themake_secret_scope
function creates a new secret scope with a unique name generated using a random name generator, and automatically deletes the scope after the test is complete. Themake_secret_scope_acl
function manages ACLs for secret scopes, defining permissions for principals (users or groups) on specific secret scopes. Three new test functions have also been added to test the functionality of creating secret scopes and managing their ACLs using these new functions. Additionally, type hints have been added to the package to support PEP 561. Overall, these changes improve the documentation and testing of the project, making it easier for developers to understand and use these new functions for managing secret scopes and their ACLs in a Databricks Workspace.make fmt
(#34). In this release, themake fmt
command in the documentation has been updated to include an additional step that runs thegen-readme.py
script before executinghatch run fmt
. This new script generates or updates the README file with detailed documentation on various PyTest fixtures available in the Python Testing for Databricks project. A newFixture
dataclass has been introduced to represent a fixture's metadata, and thedatabricks.labs.pytester.fixtures.plugin
module is used to discover all fixtures. TheFIXTURES
section in the README.md file has been updated with the new documentation, which includes information on the purpose, parameters, return values, and usage examples for each fixture. Thetest
andlint
targets in the Makefile remain unchanged. Please note that this project is not officially supported by Databricks..env
files (#36). In this change, we have added support for.env
files to the open-source library, allowing for local debugging and integration tests in IDEs. A newdebug_env_name
fixture has been introduced, which enables specifying the name of the debug environment with a default value of.env
. If there are security concerns about using.env
files, a~/.databricks/debug-env.json
file can be used instead. Additionally, we have updated thegen-readme.py
script and theFixture
class to improve documentation and provide information about the relationships between fixtures and.env
files. Thedebug_env
fixture has been added to read adebug-env.json
file if the code is running in debug mode, and theenv_or_skip
fixture has been updated to skip tests if required environment variables are not set. These changes improve the testing capabilities of the library, allowing for easier management and integration of environment variables in tests.with_user_agent_extra
method in the "init.py" file. This method, sourced from the "databricks.sdk.core" package, enables the attachment of an extra user agent string to HTTP requests, which includes the version of thepytester
project. The "about.py" file's__version__
variable is utilized to ensure the specific version of thepytester
project is incorporated in the user agent string. This enhancement allows for the tracking of project usage and statistics through user agents, providing valuable insights for future development and improvements.unwrap.py
file to thedatabricks/labs/pytester/fixtures
directory to support unit testing of pytest fixtures. We have also added unit tests for test fixtures in various files, ensuring that the fixtures behave as expected, thereby improving the reliability and stability of the codebase. Lastly, we have added a new unit test file for testing catalog functionality, specifically for themake_table
function, which creates a new managed table with a specified schema and table type.sql_backend
,sql_exec
, andsql_fetch_all
for testing SQL-related functionality in the Databricks platform. These fixtures are demonstrated in the newly addedrandom_string
test case. The commit also introduces a new sectionexclude_also
under the "[tool.mypy]" section in the pyproject.toml file, which provides more precise control over the lines checked during mypy type checking. Furthermore, the environment.py file has been removed, and several SQL backend and test resource purge time-related fixtures have been deleted, resulting in increased unit testing coverage. Additionally, thecatalog.py
andcompute.py
files in thedatabricks/labs/pytester/fixtures
directory have been updated to improve resource management and ensure proper handling after tests are executed. Thepermissions.py
file has been modified to remove thesql/
prefix from permission paths for dashboards, alerts, and queries, simplifying the permission hierarchy in the tests. Theplugin.py
file has been updated to reorganize SQL and environment-related functions, making them more modular and maintainable. Finally, new utility fixtureswatchdog_remove_after
andwatchdog_purge_suffix
have been added in thewatchdog.py
file to manage and purge test objects as needed, and a new file,.env
, has been added to thetests/unit/fixtures/
directory to provide consistent testing conditions. These changes contribute to a better testing environment and improved overall project quality.ws
fixture in the Databricks testing project has been significantly enhanced in the README file. Thews
fixture now has more comprehensive documentation, including its purpose, usage example, and the fact that it is built on top of other fixtures. Additionally, the Fixture class in the gen-readme.py script has been improved for better readability and clarity. Themake_random
function in the baseline.py file has been refactored for improved documentation and clarity, with updated usage examples and the removal of a deprecatedReturns
section. These changes aim to provide clearer and more comprehensive documentation for users, making it easier to understand and utilize the features effectively.make_warehouse_permissions
,make_lakeview_dashboard_permissions
,log_workspace_link
,make_dashboard_permissions
,make_alert_permissions
,make_query_permissions
,make_experiment_permissions
,make_registered_model_permissions
,make_serving_endpoint_permissions
, andmake_feature_table_permissions
. These additions enable easier testing of various functionalities and linking within the workspace. Furthermore, we have included themake_authorization_permissions
fixture to facilitate testing of authorization functionalities. To aid in debugging, we have updated theLogging
section with thedebug_env_name
anddebug_env
fixtures. Lastly, we have added theworkspace_library
fixture for testing library-related functionalities in the workspace. These changes improve the overall testing experience and enable more comprehensive testing within the Databricks workspace.--import-mode=importlib
option in pytest 8.1 and above, and addressing a regression that caused mypy to fail. Additionally, we fix typing compatibility with Python 3.9 or less by replacingtyping.Self
withtyping_extensions.Self
. This update also ensures consistent path handling across environments by fixing an issue with backslashes being incorrectly converted in nodeid paths on Windows.Dependency updates: